1

I keep getting this error when I try to upload an image.

Warning: move_uploaded_file(upload/12fbb74863264bfc30324c64163e5e51.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/a7819363/public_html/login/profile.php on line 60

PHP Error Message

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phptGBJ2h' to 'upload/12fbb74863264bfc30324c64163e5e51.jpg' in /home/a7819363/public_html/login/profile.php on line 60

<?php

include('fig.php');
if($_POST) { 
 // $_FILES["file"]["error"] is HTTP File Upload variables $_FILES["file"] "file" is the name of input field you have in form tag.
  if ($_FILES["file"]["error"] > 0) {
    // if there is error in file uploading 
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
  } else {
    // check if file already exit in "images" folder.
    if (file_exists("upload/" . $_FILES["file"]["name"])) {

    } else {  
      //move_uploaded_file function will upload your image. 
      if(move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"])) {
        // If file has uploaded successfully, store its name in data base
        $query_image = "insert into profile_table";
        if(mysql_query($query_image)) {
          echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
        } else {
          echo'';
        }
      }
    }
  }
}

?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
sunshine
  • 11
  • 1
  • 4
    Check if dest folder has write permissions –  Aug 14 '16 at 18:18
  • 2
    Does the user account actually have permissions to write to the folder you're copying the image to? As a test, try skipping the upload entirely. Create a PHP script that does nothing but create a file in that folder. If it fails, it's nothing to do with the upload – Basic Aug 14 '16 at 18:18
  • As it says, `No such file or directory in /home/a7819363/public_html/login/profile.php on line 60`. Check this line if file exist or path to file is correct. – kuchar Aug 14 '16 at 18:22
  • try add `/` before `upload/" . $_FILES["file"]["name"]))` – Dave Aug 14 '16 at 18:22
  • i do get an image name to database but for some reason its not saving it to upload folder – sunshine Aug 14 '16 at 18:27
  • @Dave it's definitely not the problem... – kuchar Aug 14 '16 at 18:29
  • What is the absolute path of your "upload" folder ? – Marc Aug 14 '16 at 18:29
  • @kuchar several months ago I have the same problem and my solution is missing `/` :-) – Dave Aug 14 '16 at 18:30
  • @sunshine tell me what is the path to file of code from example, and to upload folder – kuchar Aug 14 '16 at 18:30
  • /public_html/upload – sunshine Aug 14 '16 at 18:31
  • make path like this `"/home/a7819363/public_html/upload/"` – kuchar Aug 14 '16 at 18:33
  • then maybe appending the whole path could resolve your problem, try this : move_uploaded_file($_FILES["file"]["tmp_name"],"/home/a7819363/public_html/upload/" . $_FILES["file"]["name"]) – Marc Aug 14 '16 at 18:33
  • @Dave its imposible.. try to type `cd /` in linux console and see what happens – kuchar Aug 14 '16 at 18:34
  • does not work : Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpSdzxWa' to '/home/a7819363/public_html/uploa‌​d/133px-Ankh-Symbol_svg.png' in /home/a7819363/public_html/login/profile.php on line 60 – sunshine Aug 14 '16 at 18:38
  • can you open the file /etc/apache2/envvars and tell what is the value at the line " export APACHE_RUN_USER= " ? – Marc Aug 14 '16 at 18:43
  • 2
    because that's look like a linux permissions issue – Marc Aug 14 '16 at 19:01
  • can you do the following command `ls -l` in that directory to see who the owner of the files is. Your apache worker doesn't seem to own the files, hence the error (*as Marc noted above about permissions^^*) – Darren Aug 15 '16 at 00:30

0 Answers0