Using the OSX system, using Mamp Pro as a virtual server, and using PHP as the backend language for file uploads, copying files from the Temp folder is
Move_uploaded_file
The code is as follows:
1 if($_files[' file '] [' ERROR ']>0){2echo ' File Error ';3}Else{4echo ' upload: '. $_files[' file ' [' name ']. ' <br> ';5echo ' type: '. $_files[' file ' [' type ']. ' <br> ';6echo ' Size: '. $_files[' file ' [' Size ']. ' <br> ';7Echo ' stored in: '. $_files[' file ' [' Tmp_name ']. ' <br> ';8 if(File_exists ("upload/". $_files[' file '] ["name"]))9 {Tenecho $_files[' file ' ["Name"]. "already exists."; One } A Else - { -Move_uploaded_file ($_files[' file '] ["Tmp_name"], the"Upload/". $_files[' file ' ["Name"]]); -echo "Stored in:". " /applications/mamp/htdocs/learnphp/upload/". $_files[' file ' ["Name"]]; - } -}
Operation Error:
[23-mar-2016 22:01:39] PHP Warning: In/applications/mamp/htdocs/learnphp/upload.php to line 18[23-mar-2016 22:01:39] php Warning: move_uploaded_file () [<a href= ' function.move-uploaded-file ' >function. Move-uploaded-file</a>]: Unable to move '/applications/mamp/tmp/php/phpbeg1al ' to ' upload/visualize_pnas.py ' in /applications/mamp/htdocs/learnphp/upload.php on line 18
The main error is
Failed to open Stream:permission denied
This means that PHP does not have folder write permissions, because only owner has write permissions. We need to change the owner of this folder to httpd owner:
$ ps aux | grep httpd
The result is:
_www 68160 0.0 0.0 2487444 100?? S 10:10 pm 0:00.00/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 68159 0.0 0.0 2487444 108?? S 10:10 pm 0:00.01/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 68154 0.0 0.0 2487444 108?? S 10:10 pm 0:00.03/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66607 0.0 0.0 2487444 108?? S 8:34 pm 0:00.09/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66301 0.0 0.0 2487444 108?? S 8:15 pm 0:00.06/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66294 0.0 0.0 2487444 108 ?? S 8:15 pm 0:00.04/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66293 0.0 0.0 2487444 108?? S 8:15 pm 0:00.06/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66292 0.0 0.0 2487444 108?? S 8:15 pm 0:09.47/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66291 0.0 0.0 2487444 108?? S 8:15 pm 0:07.27/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66290 0.0 0.0 2487444 108?? S 8:15 pm 0:00.08/applications/mamp/library/bin/httpd-f/library/application support/appsolute/mamp PRO/conf/httpd. Conf-k start_www 66097 0.0 0.0 2472172 76?? S 8:15 pm 0:00.00/applications/mamp/library/bin/
The first column is _www, so the owner of httpd is _www.
Next, modify the owner of the folder:
That's it! Let's verify now:
Look at the owner of this folder:
Go to the File parent directory:
$ cd/applications/mamp/htdocs/learnphp/
To view the owner of a subdirectory:
The result is:
Drwxr-xr-x 3 Yellow admin 102 3 20:27 files-rw-r--r-- 1 Yellow admin 277 3 19:42 index.htmldrwxr-xr-x 4 _www admin 136 3 23:07 upload- rw-r--r-- 1 Yellow admin 792 3 10:50 upload.php-rw-r--r-- 1 Yellow Admin 275 3 21:10 welcome.php
We can see that the owner of the upload folder is already _www, but then the user will be prompted to enter the administrator password when they modify the folder in the normal operation.
PHP File upload failed