Jump to content

Emailing files, using temporary name instead of storing before hand.


iarp

Recommended Posts

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";
}
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.