failed to open stream error with move_uploaded_file()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ifedi
    New Member
    • Jan 2008
    • 60

    failed to open stream error with move_uploaded_file()

    In testing out a file upload script on my developer machine, I repeatedly came up with an error message. The goal was to upload pictures from a registration form into the folder 'clientpics' located somewhere within the htdocs (server) folder. Here's the message:

    Code:
    Warning:  move_uploaded_file(C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/doc/images/clientpics/nurses.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\doc\client_reg_page.php on line 25
    Code:
    Warning:  move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Users\ifedi\AppData\Local\Temp\PHP\upload\php1C02.tmp' to 'C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/doc/images/clientpics/nurses.jpg' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\doc\client_reg_page.php on line 25
    Configuration: Windows Vista Home Premium running Apache with PHP and MySQL.
    Actually, I'm practically convinced this has to do with Windows file permissions. Months ago, I had a similar headache, which I eventually was able to overcome by doing some editing on the sharing/permissions properties of the innermost directory (say 'clientpics') . This I did by following a step-by-step instruction I stumbled upon somewhere on the web. Unfortunately, that system was lost when the laptop got missing.
    Now, I'm having to redo everything from scratch, and I really do need help here!
    Finally, apologies for a rather lengthy post.
    Regards,
    Ifedi.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    This doesn't seem to be a permission error tho. It's a "file not found" error.
    Are you sure the directory you are using exists and that the path is spelled correctly?

    Try using file_exists on the directory before you move the file, just to see if PHP can see it.

    Comment

    • ifedi
      New Member
      • Jan 2008
      • 60

      #3
      thanks Atli for taking time to reply.

      I ended up overcoming my problem when I stumbled on these results (which rather surprised little me!):

      Code:
      $available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics/');
      var_dump($available);
      Output: bool(false)

      Code:
      $available= is_writable($_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics'); //note absence of trailing forward slash
      var_dump($available)
      Output: bool(true)

      The rest of the script panned out nicely afterwards:

      Code:
      $uploaddir = $_SERVER['DOCUMENT_ROOT'].'/doc/images/clientpics';
      
      $uploadfile = $uploaddir .'/'.basename($_FILES['upload_pic']['name']);
      
      if (move_uploaded_file($_FILES['upload_pic']['tmp_name'], $uploadfile)) {
         $msg = "File is valid, and was successfully uploaded.";
      } else {
         $msg = "Error uploading!";
      }
      Just thought I should 'epilogue' the post, for the possible benefit of some folk somewhere.

      Regards,
      Ifedi
      Last edited by gits; Feb 17 '20, 08:27 AM. Reason: fixed code tags for readability

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Nice. Glad you found a solution.
        And thanks for sharing it.

        Comment

        • oussamabl
          New Member
          • Feb 2020
          • 1

          #5
          thank you bro for sharing the solution

          Comment

          Working...