PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 23, 2022

[FIXED] Get image from local path in php

 January 23, 2022     cakephp, excel, image, php     No comments   

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

  1. 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.
  2. Give the url of the image (http://website/path/image.jpg)
  3. 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
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing