I am creating a simple form that let user "upload" a file, and a comments box. after the user choose the file(can be image or pdf) and click submit, i am not gonna store the file into my web server, the file will be inserted into an email and send to me.
my question is: how can i attach the file without storing it in any place.
I don't want to use third party module.
Update:
$attachment = $_FILES["OrderList"]["tmp_name"];
$content = file_get_contents($attachment);
$content = chunk_split(base64_encode($content));
I got an error:
Filename cannot be empty in C:\dir\orders\upload.php on line 24
line 24 is $content = file_get_contents($attachment);
Today i ran into similar situation and found a solution , so here it is
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
$newname= $_FILES["file"]["tmp_name"].".".$extension;
rename($_FILES["file"]["tmp_name"],$newname);
$attachments = array( $newname );
wp_mail('emailto send', 'title', 'message','',$attachments );
}
You have already stored it when you accept the file-upload from PHP.
Simply use it when it is stored in the tmp folder.
PHP will automagically delete it for you when your script ends.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With