PHP File Upload Help

守給你的承諾、 提交于 2019-12-20 07:52:57

问题


<html><head><title>File Upload</title></head>
<body bgcolor = "lavender"><div align = "center">
<?php
if (isset($_FILES['file']) && move_uploaded_file(
$_FILES['file']['name']))
{
echo "<font color = 'green'>The file has been uploaded.</font>";
}
else echo "<font color = 'red'>There was an error uploading the file.</font>";
?>
</div></body>
</html>

This is my code. I am trying to upload a file via a seperate form in a seperate webpage, using the method 'get'. The code to the form as shown is here:

<form enctype="multipart/form-data" action = "fileupload.php" method = "get">
<input type = "file" name = "file"><br>
<input type = "submit" value = "Upload">
</form>

For some reason I keep on getting the error message - although I'm pretty sure I'm doing it right. This is my first time doing this, suggestions would be appreciated.


回答1:


it should be tmp_name

if (isset($_FILES['file']) && move_uploaded_file($_FILES['file']['tmp_name'],'ftp/' . $_FILES['file']['name']))

and do not send it as GET

<form enctype="multipart/form-data" action = "fileupload.php" method = "post">

(changed get to post)




回答2:


I'm guessing you would need to supply a destination in the move-uploaded-file function as an argument. If the move to the destination (in this case non-existent) cannot be accomplished, it would return false, which is why it would go to your else{} condition.




回答3:


move_uploaded_file() requires a $destination parameter as it's second argument. This should be set to the path at which you want to save the file.




回答4:


You cannot send the file through $_GET. You should use POST as your method for the form.



来源:https://stackoverflow.com/questions/7375565/php-file-upload-help

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!