I have tried to set image in database using blob datatype and retrieve from database using codeigniter
this is my viewfile to retrive image from database
Database
VIEW
<img src="<?php echo site_url("imageUpload/loadImg/")?>/3">
controller
function loadImg($id){
$this->load->model("imageUploads");
$rec = $this->imageUploads->getimage($id);
$ext = $this->imageUploads->getext($id);
$this->output->set_header('Content-type: image/'.$ext);
echo $rec;
}
Model
function getimage($image){
$query2 = $this->db->query("SELECT images FROM windows_users_image_upload WHERE user_id = $image")->row();
return $query2->images;
}
function getext($id){
$query = $this->db->query("SELECT ext FROM windows_users_image_upload WHERE user_id = $id")->row();
return $query->ext;
}
But its return me text not image.
Please Help Me to Retrive image from blob datatype
using codeigniter.
I used this to retrieve blob image
<img src="<?php echo 'data:' . $uploaded->file_type . ';base64,' . base64_encode($uploaded->image_data); ?>" width="200" />
Related
I'm trying to referencing an image I Laravel but I don't know how to adding
<img src="{{ asset('images/avatar/helmet/'.Auth::user()->avatar()->first()->helmet.'.png')}}">
Did you save the file name with its original extension in the data base? If so, the code below should work.
<img src="{{ asset('images/avatar/helmet/'.Auth::user()->avatar)}}">
I will recommend to save the file with its original extension by adding ->getClientOriginalExtension().
It will look like this:
$image = $request->file('imagename');
if (isset($image))
{
$imagename = uniqid() .'-'. $image->getClientOriginalExtension();
if (!file_exists('Uploads/Media/Slider'))
{
mkdir('Uploads/Media/Slider', 0777 , true);
}
$image->move('Uploads/Media/Slider',$imagename);
}else {
$imagename = 'slider.png';
}
I tried different ways, but so far nothing. There are similar topics here but they don’t seem to address my particular situation. I’d like to display a single user profile image from an “images” table with a foreign key link to a “users” table. I have a scenario that works but it’s displaying multiple images with a “foreach” statement. The images are also saved in the local “uploads” folder in the root directory. Here is the code that works for multiple images in the view:
<?php foreach($images_model as $images):?>
<img src="<?php echo base_url()."uploads/".$images->fileName;?>" alt="" class="img-thumbnail">
Where “fileName” is the column from the “images” table. The images_model looks like this:
function get_images(){
$this->db->from('images');
$this->db->order_by('date_uploaded', 'asc');
$query = $this->db->get();
return $query->result();
}
The image-upload section from the controller is below:
if($this->upload->do_upload()) {
$file_data = $this->upload->data();
$data['user_id'] = $this->session->userdata('user_id');
$data['fileName'] = $file_data['file_name'];
$data['filePath'] = $file_data['full_path'];
$data['fileType'] = $file_data['file_type'];
$data['fileSize'] = $file_data['file_size'];
$data['date_uploaded'] = date('Y/m/d H:i:s');
}
Here is the necessary portion of the ‘images’ table:
Is there a painless way to display a single image from the “images” table that would take into account the active “user_id” which is the foreign key in the “images” table? In other words, to display a user’s desired image as profile.
Thank you for helping. Appreciate any and all input.
In your model function get_images you are getting all the records from the table so multiple images are displaying.
You have user_id in your session use it to get one user record.
Controller
public function SingleUserImage(){
$data['images'] = $this->images_model->get_images();
return $this->load->view('filename', $data);
}
Change model query like this
MODEL
function get_images(){
return $this->db->get_where('images', ['user_id' => $this->session->userdata('user_id')])->row();
}
You have single user record(only one row) so no need to use foreach loop
View
According to table data that you have provided, image full path is saved use only variable in the src attribute of img tag
<img src="<?php echo $images->fileName;?>" alt="" class="img-thumbnail">
Update:-
According to your requirement with the loop use this
<?php foreach($images_model as $images):
if($images->user_id == $this->session->userdata('user_id')):?>
<img src="<?php echo base_url()."uploads/".$images->fileName;?>" alt="" class="img-thumbnail">
<?php endif; endforeach;?>
I need to retrieve an order from Magento by its id.
How do I load a specific order by id?
so far i have tried this:
<?php
$orderNumber = 145000013;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
// get order item collection
$orderItems = $order->getItemsCollection();
foreach ($orderItems as $item){
$product_id = $item->product_id;
$product_sku = $item->sku;
$product_name = $item->getName();
$_product = Mage::getModel('catalog/product')->load($product_id);
$cats = $_product->getCategoryIds();
$category_id = $cats[0];
$category = Mage::getModel('catalog/category')->load($category_id);
$category_name = $category->getName();
echo "orderNumber=".$orderNumber."<br/>";
echo "orderValue=".$orderValue."<br/>";
echo "product_name=".$product_name."<br/>";
echo "product_id=".$product_id."<br/>";
echo "product_sku=".$product_sku."<br/>";
echo "category_id=".$category_id."<br/>";
echo "category_name=".$category_name."<br/><br/>";
}
?>
it works fine for static order...but i want to get dynamically.
First you need to create a form that post to a custom controller that include your code as above
Then update your code with
$orderNumber = $this->getRequest()->getParams('field_name');;
$order = Mage::getModel('sales/order')->loadByIncrementId($orderNumber);
See this How to get post data variables after submition a form in magento
For this you need to follow the following steps:
Create a form to search for order details
You can add your custom code on your desired location.
Then you need to submit your search form on the URL where you want to show the order details. there must be one template file associated with the form submitted URL.
In the Template file you can use your above specified code. but as you want to make it dynamic need to fetch submitted order number using the following way:
$orderId = $this->getRequest()->getParam('search_orderid'); //search_orderid is name of search box
Search Form:
<form id="orderSerchForm" method="post" action="<?php echo $this->getUrl('sales/order/history') ?>">
<input type="text" name="search_order" id="search_order" placeholder="Enter Order ID" />
<input type="submit" />
</form>
I want to get image of products on order succes page of magento here is the code
<?php
$order = Mage::getModel('sales/order')->loadByIncrementId(Mage::getSingleton('checkout/session')->getLastRealOrderId());
foreach ($order->getAllItems() as $item) {
//Need image code here
}
?>
Does anybody know how to get product image on onepage success page
Thank you
Check this peace of code for image with thumbnail
<?php
$model = Mage::getModel('sales/order') //getting product model
$_product = $model->load(Mage::getSingleton('checkout/session')->getLastRealOrderId()); //getting product object for particular product id
echo $_product->getImageUrl(); //product's image url
echo $_product->getSmallImageUrl(); //product's small image url
echo $_product->getThumbnailUrl(); //product's thumbnail image url
?>
$orderIcrementId = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($orderIcrementId);
$orderItems = $order->getAllItems();
foreach($orderItems as $orderItem):
$_product = Mage::getModel('catalog/product')->load($orderItem->getProductId());
$product_small_image_path = Mage::helper('catalog/image')->init($_product, 'small_image')->resize(135);
$product_thumbnail_path = Mage::helper('catalog/image')->init($_product, 'thumbnail')->resize(56);
endforeach;
I do not know how to store an image in db and display it?
What i want to do is to store image path in db and store the image in /img/ folder and then display it to the user.
In my registration form i am asking user to upload image like this
<?php echo $this->Form->input('image', array('class'=>'forminput', 'label' => 'Upload Image:', 'type' => 'file')); ?>
and in database type of image field is longblob.
Displaying it to the user like this...
<?php echo $this->html->image('Auth.User.image');?>
You store the image on the server and in the DB you save only the name of the image.
Usualy the images are stored in img folder in webroot. When you will display the image you will have something like this:
<?php echo $this->Html->image('img' . DS . CakeSession::read('Auth.User.image')); ?>
where image is the name of the image you are uploading saved to the image field in the Users table.
Inside the controller you should upload the file as you do normaly in PHP.
$file_name = $_POST['User']['name'];
$tmp_file = $_POST['User']['tmp_name'];
if(is_uploaded_file($tmp_file)){
if(move_uploaded_file($tmp_file){
...
$this->data['User']['image'] = $file_name;
$this->User->save($this->data);
}
}
paste it in your controller and change the field and model names accroding to
public function add() {
$this->set('status_tbl', $this->Player->Status->find('list'));
if ($this->request->is('post')) {
$this->Player->create();
if(!empty($this->request->data)){
if(!empty($this->request->data['Player']['image']['name'])){
$file = $this->request->data['Player']['image'];
$ext = substr(strtolower(strrchr($file['name'], '.')), 1);
$arr_ext = array('jpg', 'jpeg', 'gif');
if(in_array($ext, $arr_ext)){
$this->request->data['Player']['image'] = $file['name'];
move_uploaded_file($file['tmp_name'],'uploads/file'.$file['name']);
$this->Player->save($this->request->data);
}
}
if($this->Player->save($this->request->data)){
return $this->redirect(array('controller'=>'Players',"action"=>'index'));
}
}
}
}