Miko Posted November 4, 2010 Share Posted November 4, 2010 Hi, I can't believe after more then a year I'm stuck with the simplest upload script. Here's my code: <?php if( isset($_POST['upload']) ){ $uploaddir = "uploads/"; $uploadfile = $uploaddir.$_FILES['fileupload']['name']; if( move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile) ){ echo "Upload OK!"; }else{ echo "Upload FAILED!!!"; } }else{ ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" name="upload" method="post"> <input type="file" name="fileupload" /> <input type="submit" name="upload" value="upload" /> </form> <?php } ?> this is the simplest php upload script that you can find, though the least secure one (it's for a local pc project). When I try to upload any file it gets to my else statement. Anyone an idea why? I don't see it Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/217761-upload-file-problem/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 4, 2010 Share Posted November 4, 2010 Your code is not checking for any of the possible upload errors before attempting to move the uploaded file, so it is not able to tell you why the upload is failing and neither can we. You should both be doing this on a system with error_reporting set to E_ALL and display_errors set to ON so that all the php detected errors will be reported and displayed AND you need error checking and error reporting logic in your code to test if the upload was successful before attempting to access any for the uploaded file information. Doing the above would tell you that none of your $_FILES['fileupload'][...] variables are set. When you backtrack this problem to your form, you will find that the <form> tag is missing the enctype= attribute necessary to upload files. Quote Link to comment https://forums.phpfreaks.com/topic/217761-upload-file-problem/#findComment-1130331 Share on other sites More sharing options...
Miko Posted November 4, 2010 Author Share Posted November 4, 2010 ow yeah, .. why didn't I think of that ... thanks Quote Link to comment https://forums.phpfreaks.com/topic/217761-upload-file-problem/#findComment-1130334 Share on other sites More sharing options...
Miko Posted November 4, 2010 Author Share Posted November 4, 2010 Okay, it's working, thanks mate! Quote Link to comment https://forums.phpfreaks.com/topic/217761-upload-file-problem/#findComment-1130339 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.