php:
//This is the directory where images will be saved
$target = "/images/";
$target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$strListItemPic=(mysql_real_escape_string($_FILES['photo']['name']));
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). "
has been uploaded, and your information has been added to the directory";
}
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
}
HTML:
<input type="hidden" name="size" value="350000">
<input type="file" name="photo">
Это вспыхивает и дает "Sorry, there was a problem uploading your file.";
Я вставляю $ strListItemPic позже в оператор MySQL, чтобы я мог отобразить изображение в переменной в другом месте
Есть ли явные ошибки в этом коде? Должен ли мой $ target быть абсолютными путями?
Ошибки PHP:
Warning: move_uploaded_file(/xxxxxx/lists/images/test.gif):
failed to open stream: No such file or directory in
/home/virtual/site48/fst/var/www/html/xxxxxx/lists/itemedit.php on line 22
Warning: move_uploaded_file(): Unable to move '/tmp/phpJ3v7HV' to
'/xxxxxx/lists/images/test.gif'
in /home/virtual/site48/fst/var/www/html/xxxxxx/lists/itemedit.php on line 22
Исправлено:
Added enctype="multipart/form-data" to <form>
Removed / before images in $target