0

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

2
  • its clear in warning message. you need to give write permission in your uploaded path Commented Mar 2, 2015 at 4:52
  • How can i do that? Please explain.Thank You Commented Mar 2, 2015 at 4:53

2 Answers 2

3

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..

Sign up to request clarification or add additional context in comments.

Comments

0
bool is_writable ( string $filename_or_directory )

Will tell you is directory of file is writable

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.