我使用教程仅将图像上传到我的服务器我似乎无法让它实际将图像放置在我服务器上的文件夹中?
我有以下...
if (isset($_POST['submit'])) {
$allowedExts = array("jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("/upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"/upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "/upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
};
任何人都可以看到有什么问题吗?正如我所说,我收到一条成功消息,但正确的文件夹中似乎没有任何内容......
html
<form action="#" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
Array
(
[file] => Array
(
[name] => Screen shot 2012-12-16 at 8.40.49 PM.png
[type] => image/png
[tmp_name] => /tmp/phpVr7glY
[error] => 0
[size] => 6289
)
)