PHP:文件上传 move_uploaded_file() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9952329/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
PHP: File upload move_uploaded_file() not working
提问by SnarkyDTheman
I just made a file upload code and I was wondering why the file upload wasn't working. I changed the upload dir to 0777. This is my upload HTML code:
我刚刚制作了一个文件上传代码,我想知道为什么文件上传不起作用。我将上传目录更改为 0777。这是我的上传 HTML 代码:
<form action="upload_file.php" 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>
And PHP Code:
和 PHP 代码:
<?php
if ($_FILES["file"]["error"] > 0){
echo "Error Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Uploaded file: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kilobytes<br />";
if (file_exists("/files/".$_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. No joke-- this error is almost <i><b>impossible</b></i> to get. Try again, I bet 1 million dollars it won't ever happen again.";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],"/filebro/".$_FILES["file"]["name"]);
echo "Done";
}
}
?>
So, what could the problem possibly be?
那么,问题可能是什么?
回答by segrived
Try
尝试
move_uploaded_file($_FILES["file"]["tmp_name"],"filebro/".$_FILES["file"]["name"]);
回答by Thomas Mavrofides
Your
您的
if (file_exists("/files/".$_FILES["file"]["name"]))
will always return false. The file is saved with its temp name.
将始终返回 false。该文件以其临时名称保存。
Try
尝试
if (is_uploaded_file($_FILES["file"]["tmp_name"]))
instead.
反而。