Asday Posted July 9, 2007 Share Posted July 9, 2007 I have this code: <?php if ($_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) / 1024) . "MB<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br /><br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists, foof!"; } else { move_uploaded_file($_FILES["name"]["tmp_name"], "/upload/" . $_FILES["file"]["name"]); echo 'It`s now <a href="/upload/' . $_FILES["file"]["name"] . '">here.</a> Tell your friends!'; } } ?> Which doesn't work. When I click the "here", it pulls out a 404. The file doesn't even upload to the specified location, becuase the folder remains empty. (On another page, there is a form with the necessary things to upload a file: Textbox, browse button, submit button...) Thanks. Quote Link to comment Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 move_uploaded_file($_FILES["name"]["tmp_name"] Here is the problem, You use different variable name: 'name' instead of 'file' -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
matto Posted July 9, 2007 Share Posted July 9, 2007 Also, I see you have referenced your upload directory as "/upload/" and "upload/" Quote Link to comment Share on other sites More sharing options...
Asday Posted July 9, 2007 Author Share Posted July 9, 2007 move_uploaded_file($_FILES["name"]["tmp_name"] Here is the problem, You use different variable name: 'name' instead of 'file' -- Tapos Pal Now I get this: Warning: move_uploaded_file(/upload/1.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\uploadFile.php on line 20 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php67.tmp' to '/upload/1.jpg' in C:\xampp\htdocs\uploadFile.php on line 20 Am I using the wrong slashes? Quote Link to comment Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 Yes -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 Also, I see you have referenced your upload directory as "/upload/" and "upload/" You must saw it. U should be carefull about vriables name. -- Tapos Pal Quote Link to comment Share on other sites More sharing options...
sushant_d84 Posted July 9, 2007 Share Posted July 9, 2007 CHECK THE permissions Quote Link to comment Share on other sites More sharing options...
Asday Posted July 9, 2007 Author Share Posted July 9, 2007 Well, Matto helped a little, but I solved it myself. Thanks for trying, guys. Final code: <?php if ($_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) / 1024) . "MB<br />"; echo "Stored in: " . $_FILES["file"]["tmp_name"] . "<br /><br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists, foof!"; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo 'It`s now <a href="/upload/' . $_FILES["file"]["name"] . '">here.</a> Tell your friends!'; } } ?> 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.