tags:

views:

68

answers:

2

ho everyone i am trying to upload images but i got a warning that i didn't understand

here is the code

// print out contents of $_FILES ARRAY

print "Print out of the array of files: FILES <br>";

print_r($_FILES);

print "<br><br>";

$F1 = $_FILES["fname"];

print_r($F1);

print "<br><br>";

// 0 means a successful transfer

  if ($_FILES["fname"]["error"] > 0) {

    print "An error occurred while uploading your file";

    exit(0);
  }

// only accept jpg images pjpeg is for Internet Explorer.. should be jpeg

  if (!($_FILES["fname"]["type"] == "image/pjpeg")) {

    print "I only accept jpg files!";

    exit(0);
  }

// divide size by 1024 to get it in KB

 if ($_FILES["fname"]["size"] / 1024 > 50) {

    print "Your gif file is too large! Less that 50KB please!";

    exit(0);
  }

// check that file is not already there in your uploads folder

  if (file_exists("Uploads/" . $_FILES["fname"]["name"])) {

    print "$F1[name] already exists. Choose another name for your file.";

    exit(0);
  }


// move file from temp location on server to your uploads folder

  **move_uploaded_file($_FILES["fname"]["tmp_name"], "Uploads/".$_FILES["fname"]["name"]);**

  print "Stored in:"." Uploads/".$_FILES["fname"]["name"];


// save location of upload to text file uploads.txt for later use

$datafile = fopen("uploads.txt","a");

flock($datafile,1);

fwrite($datafile, "Uploads/".$_FILES["fname"]["name"]."\n");

flock($datafile,3);

fclose($datafile);

and the warning is( refer to bold line)

Warning: move_uploaded_file(Uploads/avatar3.jpg): failed to open stream: No such file or directory in /home/www/mariam.awardspace.info/php/posts.php on line 57

Warning: move_uploaded_file(): Unable to move '/tmp/phprqcpQB' to 'Uploads/avatar3.jpg' in /home/www/mariam.awardspace.info/php/posts.php on line 57

thanks in advance

+2  A: 

2 things come to mind.

  1. Try using a path like

    $_SERVER['DOCUMENT_ROOT'].'/path/to/file.jpg');

  2. Then make sure the uploads folder exists in the root folder of your site

David Archer
there is are two other things 3. make sure the web-server has write access to the Uploads folder,4. make sure the folder is named "Uploads" and not "uploads" - it'll be case-sensitive if it's running on a *nix server
phalacee
hmmm yeah good points. Do you know if the error for wrong permissions would still be, as in the question, file not found? I don't know...
David Archer
David - the error for permissions would indeed be different, but it's always something worth checking anyway.
phalacee
cool, thanks for getting back to me :-)
David Archer
+1  A: 

The directory "Uploads" does not exist or you don't have sufficient permissions to write to it.

stefanw