Can anyone please help me to change the directory of image in fpdf?
I needed to fetch the image from database where it is saved as my customer has given me the image. I am using laravel 5.4.
****
But FPDF is searching for image in fpdf folder.
I want to change directory to the saved folder.
//Fetching logo from database
$pdf->Image($company->logo,'10','10','30','30');
//Directories where the image is saved
Image are saved in = (public/upload/logos [folder])
In case anyone needs the answer of changing the directory of image file to fetch it for laravel in fpdf !
$path = public_path() . '/upload/logos/';
$filepath = $path . $company->logo;
if(file_exists($filepath)) {
$pdf->Image($filepath,'10','10','30','30');
}
Related
I have absolute path of my uploaded image file and i want to get image file which i uploaded in my folder. So how can i get image file and how i can upload image.So i can perform image operation like watermark and rotate. So i have to get image file in code igniter.
i tried but it is not working
$upld_file = 'my absolute path';
$real_path = realpath($upld_file);
$img = base64_encode($real_path);
and i send $img parameter to upload image
I am getting "you did not select a file to upload"
C:\wamp64\www\codeigniter_project\assets/images/1551892667300.jpeg
This is my absolute path of my image
Thank You.
You don't need to get the absolute path of the image if you are storing the images inside a assets in the root of your project directory, You can access the image like this
echo base_url('assets/images/1551892667300.jpeg');
NOTE : you need to load the url helper first
You can try like this..
//define image path
$filename="C:/wamp64/www/codeigniter_project/assets/images/1551892667300.jpeg";
// Load the image
$source = imagecreatefromjpeg($filename);
// Rotate
$rotate = imagerotate($source, 90, 0);
//and save it on your server...
imagejpeg($rotate, "savedestinationpath.jpg");
That should be the file input name. eg: If your file browse input name is myFileInput then it should be $this->upload->do_upload('myFileInput')
Also make sure that you have set attribute enctype="multipart/form-data" for your form.
One nice example is here
I am trying to write a script to upload bulk product from excel sheet which contain product name, price and images. Images are the dropbox image share link. How can I download those image from the dropbox url, save them on my server, then upload the image url to my database?
Excel sheet reading:Maatwebsite/Laravel-Excel
Generic upload code:
public function productUpload(Request $request){
if($request->hasFile('products')){
$path= $request->file('products')->getRealPath();
$data = Excel::load($path)->get();
if($data->count()){
foreach ($data as $key => $value) {
//download the image create thumbain and store to /images/product/thumbnail folder and get the link,
$thumbnail = //here will be the path for the thumbnail
//Original image
$original = ;
$data['original']= $original;
$data['thumbnail']=$thumbnail;
$data['name']=$value->name;
$data['price']= $value->price;
Product::create($data);
}
return redirect()->back()->with('success','Product has been uploaded');
}
}
}
The image url that is in the excel sheet is like this one https://www.dropbox.com/s/x2tbsy49sraywvv/Ruby12.jpg?dl=0 This file has been removed at this point.
You can dowload the image directly by adding dl=1 to the dropbox link Source
And you can dowload the image to the server with the file_get_contents php command. Source and store it in the server with the Storage Facade
$url = "yoururl"; //check if has the dl=0 and change it to 1 or add dl=1
$contents = file_get_contents($url);
$name = 'image.png';//the name of the image to store on disk.
\Storage::disk('yourdisk')->put($name, $contents);
Also you will get the full path to the image like this.
$thumbnail = storage_path('yourdir/'.$name)
Tested it with a file that i have on my dropbox and worked without a problem.
You still need to handle some things like errors and delays while dowloading the images.
Thanks for advance,
I have installed the theme then I have installed import/export
Module for products.
I have Made the CSV file according existing CSV file which I have
export through the Module. ( I have made that csv file fields
accordingly).
But there are one problem with "image_name" fields i am trying to get images form extranal server like (https://me-cdn.xyz.com/pub/media/catalog/product/V/1/V1_KHNB01649961_C2N1.jpg).
When i am importing the file all fields are stored but images not stored it's showing Opencart default image.
Please help me how will work my csv file along with images.
You are only saving image name in table actually you are not uploading image on server. opencart have a function for image resize and rending you can find function in bellow file.
catalog/model/tool/image.php
Function name is public function resize($filename, $width, $height) {
if you want your show your save image path then you can change this file through vqmod or ocmod.
For testing purpose add this line you above function
public function resize($filename, $width, $height) {
$pos = strpos($filename, 'https://me-cdn.xyz.com/pub/media/');
if ($pos !== false) {
return $filename;
}
I want to know that how can I overwrite images when they uploaded to server in php. For example I uploaded a photo to a folder as soon as I upload another image it will take place of previous image. Image name is not same it may differ. Thanks
Delete the previous image before uploading the new one using:
$path = $_SERVER['DOCUMENT_ROOT'].'img/img.jpg';
unlink($path);
This code basically assigns the path of the image to $path and deletes the image using unlink($path);
In my PHP site I have a script to upload images, see the script below
$uploaddir = $root_path."images/uploaded_images/category/";
$small_file_name = trim($_FILES['cat_image1']['name']);
$small_file_len = strlen($small_file_name);
$small_file_ext = strtolower(substr($small_file_name,-4)); // select last 4 characters
$small_uploadfile = $uploaddir. $_FILES['cat_image1']['name'];
if($small_file_len>4 and ($small_file_ext==".gif" or $small_file_ext==".jpg" or $small_file_ext=="jpeg")){
if ($small_file_ext=="jpeg")
$uniqname = uniqid(rand()).".".$small_file_ext;
else
$uniqname = uniqid(rand()).$small_file_ext;
$thumb_filename1 = "thumb_".$uniqname; // store uniqname into database
$uploadfile = $uploaddir.$uniqname; //uncomment for local testing
if (move_uploaded_file($_FILES['cat_image1']['tmp_name'], $uploadfile)) {
chmod($uploadfile,0777);
list($width, $height, $type, $attr) = getimagesize($uploadfile);
$max_width = 276;
$max_height = 162;
$a = new Thumbnail($uploadfile,$max_width,$max_height,$uploaddir.$thumb_filename1,100,'');
$a->create();
}else{
$flag=1;
$frm_server_side_error= $frm_server_side_error."Error in uploading image,";
}
}
else{
$flag=2;
$frm_server_side_error= $frm_server_side_error."Image not in gif or jpg format,";
}
After uploading in to the server its can't be see (I am displaying the thumb image). So I checked the file permission of that image through the FTP and give read permission. Thus image displays. But I give the read and write permission to the category folder and it’s parent folders. How can view the image after uploading (default read permission to the uploading files ie thumb image.)
I noticed that the actual image have read permission but the thumb image doesn't have the read permission. I need to display only the thumb image.
You have used a class Thumbnail to create a thumbnail image. But I guess you have missed to change the file permission in the new thumbnail image. Please check the code in the create() function of the class Thumbnail
Your code formatted poorly here (half is in code format, half not), but it appears you have a comment before the snippet that would copy the file from the temp location to the final location - if that's the case, the file won't exist, and thus won't be viewable.
But I could be wrong - I'm happy to take a second look if you fix the formatting.