'Permission denied for file upload in PHP
I have a problem that I can't resolve for some time now.
I am making simple file upload with PHP and XMLHttpRequest. I am taking data from a form and sending it to the backend script.
Data is sent successfully and I can display it, but I can't move uploaded image to a folder because I get an error
Warning: move_uploaded_file(image_test/cart.png): failed to open stream: Permission denied in /srv/http/portfolio/admin/backend/write/blogs.php
At first, I thought it was permissions problem but these are permissions to root folder of the project
drwxr-xr-x 9 m1ck0 m1ck0 4096 13. nov. at 21:18 portfolio
Here are permissions of images folder that I am trying to upload the image to.
drwxr-xr-x 2 m1ck0 m1ck0 4096 13. nov. at 21:18 images
Here is PHP code
$sourcePath = $_FILES['image']['tmp_name'];
$targetPath = "image_test/".$_FILES['image']['name'];
echo $targetPath;
if(!move_uploaded_file($sourcePath, $targetPath)) {
echo 'error';
} else {
echo 'done';
}
http folder is also owned by me.
Does anyone know what could I do?
I am using OS: Manjaro Linux x86_64
Solution 1:[1]
You will need to give write permission to that folder, it currently doesn't appear to have that.
You could use chmod to do this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Run_Script |
