I have an Apache server running on Amazon cloud and I am trying to upload files using PHP, however I am getting
[Tue Aug 25 13:19:20.780797 2015] [:error] [pid 5162] [client 120.59.58.80:9613] PHP Warning: move_uploaded_file(./Page1.pdf): failed to open stream: Permission denied in /var/www/html/handlefiles.php on line 8, referer: http://myhost/articles.html
My code for the same is:
$uploads_dir = './';
$fileName = $_FILES["file"]["name"];
$fileTmpLoc = $_FILES["file"]["tmp_name"];
// Path and file name01
$pathAndName = "./".$fileName;
// Run the move_uploaded_file() function here
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
echo $moveResult;
The permissions are:
drwxrwsr-x. 7 root ec2-user 4096 Aug 25 13:27 html
-rw-rw-r--. 1 root ec2-user 1222 Aug 25 13:19 handlefiles.php
Any help is appreciated.
Thanks
Firstly check user of your ec2 apache server. use below instruction ps aux | grep apache
then check user and use this code
sudo chown -R ubuntu:www-data /var/www/html/
I think that you have a problem with the folder permission. The ./ indicate the current directory that php engine probably have no right to write. First try to run the code without ./
$uploads_dir = './';
$fileName = $_FILES["file"]["name"];
$fileTmpLoc = $_FILES["file"]["tmp_name"];
// Path and file name01
$pathAndName = $fileName;
// Run the move_uploaded_file() function here
$moveResult = move_uploaded_file($fileTmpLoc, $pathAndName);
echo $moveResult;
then specify whole pass like;
$pathAndName = "/var/www/html/".$fileName;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.