jettjordan23 Posted November 10, 2007 Share Posted November 10, 2007 Hello all! I have a very short piece of code that I was hoping that someone here could help me modify. Essentially, I am attempting to code through an html form and a server side script that will allow a user to my website to upload a file to my server. As of now, the code works, but for the last 8 hours, I have been trying to modify it to no luck. What I would like the sever side script to do is to 1. Give each file uploaded a unique filename so that they do not write over other files with the same name. I was thinking about adding a timestamp to the end of each name before it is saved.. 2. Restrict the type of files uploaded to .pdfs and Microsoft word documents. Below, I have pasted both my form and my php. Any help would be greatly appreciated. I am a terrible programmer and have literally been up for 8 straight hours trying to get this to work, but too no avail. Thank you so much for all of your help! FORM <form enctype="multipart/form-data" action="fileupload2.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> SERVER SIDED SCRIPT <?php echo 'Upload result:<br>'; // At least one symbol should be sent to response!!! $uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/../"; echo '<pre>'; if(count($_FILES) > 0) { $arrfile = pos($_FILES); $uploadfile = $uploaddir . basename($arrfile['name']); if (move_uploaded_file($arrfile['tmp_name'], $uploadfile)) echo "File is valid, and was successfully uploaded.\n"; } else echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files echo 'Here is some more debugging info:'; print_r($_FILES); echo "</pre>"; ?> EDITED BY WILDTEEN88: Please use code tags ( ) Quote Link to comment Share on other sites More sharing options...
jettjordan23 Posted November 10, 2007 Author Share Posted November 10, 2007 Also, for some reason, I can only save files to my root directory. I cannot inster say "/uploads/" so that it will save in a folder called uploads. Does anyone know why this is so? 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.