上传图片:undefined index

时间:2014-05-20 03:30:06

标签: php mysql

我正在尝试使用php / mysql上传图片,我有一个错误的未定义索引:来自下面的代码的uploaded_file。我该如何解决这个问题?

PHP代码是:

<?php

$fileName = $_FILES["uploaded_file"]["name"];
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"];
$fileType = $_FILES ["uploaded_file"]["type"];
$fileSize = $_FILES ["uploaded_file"]["size"];
$fileErrorMsg = $_FILES ["uploaded_file"]["error"];
$split = explode (".", $fileName);
$fileExt = end($split);

if (!$fileTmpLoc) {
echo "ERROR: No files selected!";
exit();
} else if ($fileSize > 5242880) {
echo "ERROR: Your file was larger than 5 Megabytes in size.";
unlink($fileTmpLoc);
exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {
echo "ERROR: Your image was not .gif, .jpg, or .png.";
unlink($fileTmpLoc);
exit();
} else if ($fileErrorMsg == 1) {
echo "ERROR: An error occurred while processing the file. Try again.";
exit ();
}

$moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName");
if ($moveResult !=true) {
echo "ERROR: File not uploaded. Try again.";
unlink($fileTmpLoc);
exit();
}

?>

HTML代码为:

<form enctype="multipart/form-data" method="post" action="image_upload.php">
Choose your file here:
<input name="uploaded_file" type="file" /><br /><br />
<input type="submit" value="Upload It">
</form>

0 个答案:

没有答案