<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>";
?开发者_StackOverflow中文版>
</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.
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)
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.
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.
You cannot send the file through $_GET. You should use POST as your method for the form.
精彩评论