drivethru Posted February 17, 2007 Share Posted February 17, 2007 I need help creating a file upload script. I need users to be able to upload mpeg files only. Users will also need to be logged in by a username/password system. How can users upload files and also will let me know who uploaded the file? Any help will be greatly appreciated! Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 17, 2007 Share Posted February 17, 2007 here is my upload script: index.php: <?php echo "<table align=\"center\" width=\"100%\" cellspacing=\"0\" cellpadding=\"0\" border=\"0\">"; echo "<tr>"; echo "<td><form enctype=\"multipart/form-data\" action=\"include/upload.php\" method=\"post\">"; echo "<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"51200\">"; echo "Send this file: <input name=\"userfile\" type=\"file\">"; echo "<input type=\"submit\" value=\"Send File\">"; echo "</form></td>"; echo "</tr>"; echo "</table>"; ?> Which sends it to my upload.php where it actually does all of the uploading: upload.php: <?php $updir = 'C:\\Inetpub\\wwwroot\\upload\\'; $upload = $updir . basename($_FILES['userfile']['name']); if ($_FILES['userfile']['size'] < $_POST['MAX_FILE_SIZE']) { echo "File size limit is " . $_POST['MAX_FILE_SIZE'] . " and you have tried to upload a file size of " . $_FILES['userfile']['size'] . ".<br>"; } else { move_uploaded_file($_FILES['userfile']['tmp_name'], $upload); echo "It worked!."; } echo $_FILES['userfile']['error']; ?> Quote Link to comment Share on other sites More sharing options...
drivethru Posted February 17, 2007 Author Share Posted February 17, 2007 thanks for the help. But how can I send my uploaded file to my "upload" folder? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 all you do is set this line correctly ok. $updir = 'C:\\Inetpub\\wwwroot\\upload\\'; Quote Link to comment Share on other sites More sharing options...
drivethru Posted February 17, 2007 Author Share Posted February 17, 2007 I tried that. I changed it the location of where the file is bein sent. It says that the file uploaded, but it does not show up in my upload folder. Quote Link to comment Share on other sites More sharing options...
Archadian Posted February 17, 2007 Share Posted February 17, 2007 Is the upload folder's security set where the IUSR_%machinename% has full read, write and execute privilages? Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 try this ok. <?php chmod($updir,0007); $updir = 'C:\\Inetpub\\wwwroot\\upload\\'; $upload = $updir . basename($_FILES['userfile']['name']); if ($_FILES['userfile']['size'] < $_POST['MAX_FILE_SIZE']) { echo "File size limit is " . $_POST['MAX_FILE_SIZE'] . " and you have tried to upload a file size of " . $_FILES['userfile']['size'] . ".<br>"; } else { move_uploaded_file($_FILES['userfile']['tmp_name'], $upload); echo "It worked!."; } echo $_FILES['userfile']['error']; ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 17, 2007 Share Posted February 17, 2007 here you go i wrote this for you read it ok. <?php $id="0001"; // directory path. $uploaddir = 'upload_new/'; // get the dir to send file to and the file name. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); $file=$uploadfile; $ext = substr($file, -4); $uploadfile=$uploaddir.$id.$ext; @rename($file,$uplaodfile); // if all the conditions are correct send the file to the directory. if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){ // success echoed echo " <font color='red'>File is valid, and was successfully uploaded.</font>"; }else { //unsuccesfull echoed echo "<font color='red'>File was unsuccesful sorry</font>"; } // show the form. echo" <form enctype='multipart/form-data' action='new_test.php' method='POST'> <input type='hidden' name='MAX_FILE_SIZE' value='30000000000000000000000'> send this file <input name='userfile' type='file' > <input type='submit' name='submit' value='Send File'> </form>"; ?> 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.