Reputation: 21
I can not upload image. And i am using lampp server in ubuntu. It shows some errors that i can not figure out..
if (isset($_POST["submit"]))
{
$fileType = $_FILES["file"]["type"];
if (($fileType == "image/gif") ||
($fileType == "image/jpeg") ||
($fileType == "image/jpg") ||
($fileType == "image/png")) {
//Check if file exists
if (file_exists("Images/Coffee/" . $_FILES["file"]["name"])) {
echo "File already exists";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "Images/Coffee/" . $_FILES["file"]["name"]);
echo "Uploaded in " . "Images/Coffee/" . $_FILES["file"]["name"];
}
} }
And my errors are
Warning: move_uploaded_file(Images/Coffee/costa.png): failed to open stream: Permission denied in /opt/lampp/htdocs/newphp/uplaodimage.php on line 23
Warning: move_uploaded_file(): Unable to move '/opt/lampp/temp/phpE2uIod' to 'Images/Coffee/costa.png' in /opt/lampp/htdocs/newphp/uplaodimage.php on line 23 Uploaded in Images/Coffee/costa.png
Upvotes: 0
Views: 110
Reputation: 2177
bool is_writable ( string $filename_or_directory )
Will tell you is directory of file is writable
Upvotes: 0
Reputation: 93
You have not write permission in your directory where you store file so you have first give the write permission to your directory where you want to upload your file Like in Ubuntu:
chmod -R 777 /path..
Upvotes: 3