The full error is: Warning: move_uploaded_file(…/public_html/download/download.sql): failed to open stream: Permission denied
Running LAMP on Ubuntu 18.04, Apache 2.4, PHP 7.23
Steps I’ve taken:
- Ensured I’m a member of the www-data group
- Run “sudo chown -R www-data:www-data /var/www”
- Ensured that download and temp folders exist under /var/www/html and that they have the correct permissions.
My code follows:
$target_dir = "../public_html/download/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
if(isset($_POST["submit"])) {
if (file_exists($target_file)) { // Check if file already exists
echo "Sorry, file already exists.";
$uploadOk = 0;
}
else { // if everything is ok, try to upload file
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
}
else {
echo "Sorry, there was an error uploading your file.";
}
}
}
I don’t know where to go from here. Any help is appreciated.
Larry