用file上传文件,在tmp目录下找不到文件
代码如下:
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" charset="utf-8" /> <br />
<input type="submit" name="submit" value="Submit" />
</form>
upload.php
<?php
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"];
}
}
?>
运行结果:
Upload: jdk-6u34-windows-x64.exe
Type: application/octet-stream
Size: 61154.484375 Kb
Temp file: F:\xampp\tmp\phpCB11.tmp
Warning: move_uploaded_file(upload/jdk-6u34-windows-x64.exe): failed to open stream: No such file or directory in F:\xampp\htdocs\test\qwe.php on line 26
Warning: move_uploaded_file(): Unable to move 'F:\xampp\tmp\phpCB11.tmp' to 'upload/jdk-6u34-windows-x64.exe' in F:\xampp\htdocs\test\qwe.php on line 26
Stored in: upload/jdk-6u34-windows-x64.exe
纠结好久了,平台环境是windows平台下安装XAMPP集成环境
望高手解答,并且想知道是为什么……
[解决办法]
目录 upload 不存在
[解决办法]
可能原因:
1.路径不对。
2.文件夹没有权限。
加 dirname(__FILE__) 看看。
if (file_exists(dirname(__FILE__)."/upload/" . $_FILES["file"]["name"]))
[解决办法]
failed to open stream: No such file or directory