Issue
I am working on a bulk upload project using excel sheet and using CakePHP 3.2 for writing application.
I have an excel sheet with a column to give image to be uploaded.
User have 3 choices to go with either
- Upload images to a pre defined directory before bulk upload and give the name of the image in the cell and image will be automatically selected from path.
- Give the url of the image (http://website/path/image.jpg)
- Give the path of the image if it is on local machine. Ex., C:\user\pictures\image.jpg if windows, and /home/user/picture/image.jpg if linux
This is what I'm doing to save images
$p_image = $objWorksheet->getCellByColumnAndRow(30, $row)->getValue();
if (filter_var($p_image, FILTER_VALIDATE_URL)) {
// get image from url
$full_image_path = $p_image;
} else {
// get image from folder
$path = Configure::read('media.bulkUpload.pre.product');
// full path of the image from root directory
$full_image_path = $path . DS . $p_image;
}
$upload_path = Configure::read('media.upload') . DS . 'files' . DS;
// new name of image
$img_new_name = uniqid('img_').round(microtime(true) * 1000).rand(1,100000);
if ($full_image_path) {
// generate uuid directory name
$dir = Text::uuid();
// create new directory
mkdir($upload_path.$dir, 0777, true);
// save file
try {
$img = new \abeautifulsite\SimpleImage($full_image_path);
// save image of original size
$img->best_fit(850,1036)->save($upload_path.$dir.'/'.$img_new_name.'.jpg');
} catch(Exception $e) {
echo 'Error: '.$e->getMessage();
}
}
Image upload using url and pre ftp upload is working fine. But, how could I get image from the path of local system and then save them.
Solution
You can't do this without the users uploading the image themselves. You cannot retrieve a file from the client's filesystem from an external server where you run your php.
Answered By - rbr94
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.