I am trying to upload a file from an Android app to a Ubuntu web server with PHP 7.4.12 using this PHP script to get the uploaded file and save it into a server folder:
<?php
$file_path = "postsmedia/";
$file_path = $file_path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path) ){
echo "success";
} else{
echo "fail";
}
?>
Here you have the error log:
[Fri Nov 27 12:28:56.214230 2020] [php7:warn] [pid 29552] [client 172.31.39.159:64102] PHP Warning: move_uploaded_file(postsmedia/1606480134886.png): failed to open stream: Permission denied in /var/www/html/administrar/application/admin/subir_media_post.php on line 7
[Fri Nov 27 12:28:56.214258 2020] [php7:warn] [pid 29552] [client 172.31.39.159:64102] PHP Warning: move_uploaded_file(): Unable to move '/tmp/phpCV1Y9Z' to 'postsmedia/1606480134886.png' in /var/www/html/administrar/application/admin/subir_media_post.php on line 7
I can upload files directly to the server folder using FTP, but I guess the issue is a matter of permissions.
These are the permissions given to the server:
sudo chown -R www-data:ubuntu /var/www/html
sudo chmod -R 755 /var/www/html
sudo find /var/www/html -type f -exec chmod 644 {} \;
sudo find /var/www/html -type d -exec chmod 755 {} \;
I have also changed php.ini to allow greater files sizes to upload_max_size = 20M
What should I take into account to avoid the issue?