Jump to content

Recommended Posts

Any ideas... my server setting seem to be fine as to allowing img uploads ..

 

Send form :

<html> 
<body>
  <form enctype="multipart/form-data" action="upload.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
    Choose a file to upload: <input name="uploaded_file" type="file" />
    <input type="submit" value="Upload" />
  </form> 
</body> 
</html>

 

The upload script :

<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file is JPEG image and it's size is less than 350Kb
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["size"] < 350000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}
?>

 

 

The Bloody ERROR :

 

Warning: move_uploaded_file(c:\Inetpub\wwwroot\upload/upload/334475.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in c:\Inetpub\wwwroot\upload\upload.php on line 16

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\PHP\uploadtemp\php32.tmp' to 'c:\Inetpub\wwwroot\upload/upload/334475.jpg' in c:\Inetpub\wwwroot\upload\upload.php on line 16

Error: A problem occurred during file upload!

Link to comment
https://forums.phpfreaks.com/topic/69068-solved-failed-to-open-stream/
Share on other sites

ok, hrmm.  next try echoing

 

echo "$_FILES['uploaded_file']['tmp_name']";

and make sure that that 1)that variable has the correct data and 2)the data that the variable is referencing exists as a file in the correct directory.  I'm at work, so I can't run scripts, just using the compiler in my mind ;)

the echo returns :  C:\PHP\uploadtemp\php41.tmp

 

now i went to the server and to that directory and did not find a php41.tmp, could that be the cause...

when i upload i simply try to upload a small jpg file from my work desktop...

 

 

I placed the file i wanted to upload into the server directory where the script is supposed to upload the file to...

and the script worked and said "File already exists..." so its working but for some reason the physical upload

is where the issue is .. i think.

 

Perhaps im wrong and PHP might not have permissions to read and write to the folder its trying to copy the file to.

Where do i check and change that if needbe ?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.