Jump to content

Upload a file from client's <input type='file'


george

Recommended Posts

I copied the code right off the tutorials here. And I am getting an Error 1 error. That's all it says is error 1. Could it be that php is trying to copy the file to a place where it has no permission to copy? And if so, is there any way I can tell it where to go?Client side

<body><form action="filephp.php" id="fred" 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></body>

Server side

<?phpif ($_FILES["file"]["error"] > 0) {  echo "Error: " . $_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 />";		move_uploaded_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);	echo "Stored in: " . "upload/" . $_FILES["file"]["name"];	}?>

And Error 1 is all it says.

Link to comment
Share on other sites

this isn't where your error is coming from but

move_uploaded_file($_FILES["file"]["tmp_name"], $_FILES["file"]["name"]);	echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

wont copy the file to 'upload/', its just gonna be in whatever directory your 'filephp.php' script is in, use

move_uploaded_file($_FILES["file"]["tmp_name"], 'upload/' . $_FILES["file"]["name"]);	echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

Link to comment
Share on other sites

Progress, now php gives me Upload: Type: Size: 0 KbTemp file: Stored in: upload/So, still no file. Code the same as #1 above with the addition of

 <!-- MAX_FILE_SIZE must precede the file input field -->	<input type="hidden" name="MAX_FILE_SIZE" value="30000" />

in the form. Why is it taking me all day to figure out how to upload a file from a browser input tag of type file. :)

Link to comment
Share on other sites

it would be helpful if we could see exactly what your code is, from what you have posted I have no idea what is wrong
My code is in post 1 of this thread. I made a special tiny program just to get this part right before I integrate it in with my project. I usually do this when I am up against a wall.
Link to comment
Share on other sites

  • 1 month later...

Different browsers and different operating systems will send different MIME types to the server, you will just have to cater for them all. Does he have a mac?

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...