fruzzgle Posted July 27, 2007 Share Posted July 27, 2007 Well, I'm having trouble with a file upload page. I just started really learning php today after many failed attempts to in the past. I'm using the w3schools tutorial to php, I already know xhtml, css, and a decent amount of javascript. http://groogstestpages.freehostia.com/upload.php Here is my failed upload test upload.php <html> <head> <title> Upload Test </title> <link href="upload.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <form action="upload_file.php" method="post" encypte="multipart/form-data"> <label for="file">File:</label> <input type="file" name="file" id="file"> <input type="submit" name="submit" value="Upload"> </form> </div> </body> </html> upload_file.php <html> <head> <title> Upload Test Complete </title> <link href="upload.css" rel="stylesheet" type="text/css"> </head> <body> <div id="wrapper"> <?php if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg")) { if ($_FILES['file']['error'] > 0){ echo "Error" . $_FILES['file']['error'] . "<br />"; } else { echo "Name: " . $_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($_FILE['file']['tmp-name'], "upload/" . $_FILES['file']['name']); echo "stored in: " . "upload/" . $_FILES['file']['name']; } } else { echo "invalid file"; } ?> </div> </body> </html> I followed the tutorial like w3schools said, and I'm not the kind that copies and pastes code, I took an hour to write and understand this script. Seeing it's telling me it's an invalid file I'm thinking that means it has something to do with the beginning of the script- if (($_FILES['file']['type'] == "image/gif") || ($_FILES['file']['type'] == "image/pjpeg")) http://www.w3schools.com/php/php_file_upload.asp This is the w3 tutorial. I've taken out some of the script I didn't really want in there (like the size limit on files one) Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted July 27, 2007 Share Posted July 27, 2007 <form action="upload_file.php" method="post" encypte="multipart/form-data"> enctype is spelled incorrectly Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 27, 2007 Share Posted July 27, 2007 try to figure this out move_uploaded_file($_FILE['file']['tmp-name'], "upload/" . $_FILES['file']['name']); "upload/" <------- this is the folder that should get the uploaded file Quote Link to comment Share on other sites More sharing options...
btherl Posted July 27, 2007 Share Posted July 27, 2007 Looks like hitman got it I would also recommend changing the error message to this: echo "invalid file type: " . $_FILES['file']['type']; [/code] Or for debugging purposes, during script development only: echo "invalid file<br>"; var_dump($_FILES); Quote Link to comment Share on other sites More sharing options...
fruzzgle Posted July 27, 2007 Author Share Posted July 27, 2007 There is a folder set up called upload. I'm going to check to make sure the actual folder is upload and not uploads though @btherl: Thanks, I'll add those. Quote Link to comment Share on other sites More sharing options...
fruzzgle Posted July 27, 2007 Author Share Posted July 27, 2007 I don't know if your going to get really made because I double post but- I changed the upload.php file and fixed the spelling error. I also made the folder name the same as the one in the script and added the thing to the error message. it still didn't work and the error message didn't display the type. Edit: invalid file array(0) { } What? I didn't use arrays! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.