Reputation:
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
Upvotes: 0
Views: 277
Reputation: 10570
The directory "Uploads" does not exist or you don't have sufficient permissions to write to it.
Upvotes: 1
Reputation: 3060
2 things come to mind.
Try using a path like
$_SERVER['DOCUMENT_ROOT'].'/path/to/file.jpg');
Then make sure the uploads folder exists in the root folder of your site
Upvotes: 2