iarp Posted October 2, 2011 Share Posted October 2, 2011 I'm modifying a script I built a few months ago to allow someone to upload an attachment via a form and then email it off. It is expected that this form will receive a lot of hits and so it won't be possible to store the attachment in a folder before emailing it out (right away). Problem: If I skip the move_uploaded_file part, and just attach the tmp_name the tmp_name is how I receive it rather than the PDF that it actually is. How can i change the documents name before sending it off, without saving it to a general location. My worry with saving it is, someone uploads their copy and at the exact moment it's supposed to email off, someone somewhere else uploads theirs and it overwrites the first persons and then the email gets sent with the newest persons data. index.php <form action="process.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> process.php <?php print_r($_FILES); if ($_FILES["file"]["type"] == "text/plain") { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/248297-emailing-files-using-temporary-name-instead-of-storing-before-hand/ Share on other sites More sharing options...
iarp Posted October 2, 2011 Author Share Posted October 2, 2011 Scripts stopped working, i'm not sure what to do about using the temporary location rather than storing. Quote Link to comment https://forums.phpfreaks.com/topic/248297-emailing-files-using-temporary-name-instead-of-storing-before-hand/#findComment-1275034 Share on other sites More sharing options...
Deoctor Posted October 4, 2011 Share Posted October 4, 2011 you can do one thing add the session variable to the filename and then store the file some where and then send the file to the email address i guess sessions will not have duplicate names. or else you can do something else like if file exist then rename the uploading file or old file to something else and send the latest file. or you can generate a random string with around 15 characters and above and append the same to the file name while storing and pass the value as a cookie to other files Quote Link to comment https://forums.phpfreaks.com/topic/248297-emailing-files-using-temporary-name-instead-of-storing-before-hand/#findComment-1275534 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.