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. Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/ 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 Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293175 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/" Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293178 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? Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293181 Share on other sites More sharing options...
tapos Posted July 9, 2007 Share Posted July 9, 2007 Yes -- Tapos Pal Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293188 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 Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293192 Share on other sites More sharing options...
sushant_d84 Posted July 9, 2007 Share Posted July 9, 2007 CHECK THE permissions Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293197 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!'; } } ?> Link to comment https://forums.phpfreaks.com/topic/59062-solved-upload/#findComment-293221 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.