-2

I am new to PHP but have experience in .net. I need to know a way to save images uploaded to a PHP page in a subdirectory of that page and return its path. I have checked and not found a way to give permission to an existing subdirectory in PHP. I am using wamp for development.

  1. passed subdirectory in file_put_contents with the image file name.
  2. got full path and appended the subdirectory.
$ImagePath = __DIR__.'/driverimages/'.$ImageName ;
file_put_contents($ImagePath, base64_decode($data->profilepic));

I know that if I create a directory from a PHP script with 0774 permission I can write to it. But I need to write to an existing subdirectory and return the image path so that it can be used in the front end to show the image.

I need to be able to write to a subdirectory from the current directory and return the path of the written image file.

Ganesh Kumar
  • 93
  • 1
  • 12
  • I don't want to argue over this. You have given your remark by downvoting and that's ok. Thanks but I will find my way. – Ganesh Kumar Aug 26 '19 at 10:50
  • Are you sure the the `driverimages` folder exists below the folder that contains this script? On windows folder access permissions are almost never the issue, unless you have done something very odd to your windows system – RiggsFolly Sep 05 '19 at 09:05
  • Add [error reporting](http://stackoverflow.com/questions/845021/) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Sep 05 '19 at 09:06

1 Answers1

1

$ImagePath = __DIR__.'/driverimages/'.$ImageName;

mkdir(dirname($ImagePath),777);

file_put_contents($ImagePath, base64_decode($data->profilepic));

dılo sürücü
  • 3,821
  • 1
  • 26
  • 28