Jump to content

dynamically selecting the file from a folder


barrowvian

Recommended Posts

Ive got the image upload function working. If everything is ok I make a new directory and move the file to it;

		mkdir("tempimages" . "/temp." . $_SESSION['firstname'] . $_SESSION['lastname'], 0777); //make temp dir
	$upload_path = "tempimages" . "/temp." . $_SESSION['firstname'] . $_SESSION['lastname'] . "/";
	move_uploaded_file($_FILES["$img"]['tmp_name'],$upload_path . "$imgname." . $pathinfo['extension']);

 

Then Im wanting to use this specific file to attach to an email. The file type can be either .jpg or .gif

 

Ive found this piece of code online;

		$to =	 '[email protected]';
	$subject =	 'PHP Mail Attachment Test';
	$bound_text =	"sometext";
	$bound =	"--".$bound_text."\r\n";
	$bound_last =	"--".$bound_text."--\r\n";

	$headers =	"From: [email protected]\r\n";
	$headers .=	"MIME-Version: 1.0\r\n"
		."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

	$message .=	"If you can see this MIME than your client doesn't accept MIME types!\r\n"
		.$bound;

	$message .=	"Content-Type: text/html; charset=\"iso-8859-1\"\r\n"
		."Content-Transfer-Encoding: 7bit\r\n\r\n"
		."hey my <b>good</b> friend here is a picture of regal beagle\r\n"
		.$bound;

	$file =	file_get_contents("http://www.litfuel.net/php/regal_004.jpg");

	$message .=	"Content-Type: image/jpg; name=\"regal_004.jpg\"\r\n"
		."Content-Transfer-Encoding: base64\r\n"
		."Content-disposition: attachment; file=\"regal_004.jpg\"\r\n"
		."\r\n"
		.chunk_split(base64_encode($file))
		.$bound_last;
	if(mail($to, $subject, $message, $headers)) 
	{
     		echo 'MAIL SENT'; 
	} else { 
     		echo 'MAIL FAILED';
	}

 

How would I go about changing the parts of the code to select the file that Ive just uploaded? Thanks

 

Nevermind I've solved it with a bit of experimenting :)

 

$to = '[email protected]';

$subject = 'PHP Mail Attachment Test';

$bound_text = "darren2012";

$bound = "--".$bound_text."\r\n";

$bound_last = "--".$bound_text."--\r\n";

 

$headers = "From: [email protected]\r\n";

$headers .= "MIME-Version: 1.0\r\n"

."Content-Type: multipart/mixed; boundary=\"$bound_text\"";

 

$message = "If you can see this MIME than your client doesn't accept MIME types!\r\n"

.$bound;

 

$message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"

."Content-Transfer-Encoding: 7bit\r\n\r\n"

."hey my <b>good</b> friend here is a picture of regal beagle\r\n"

.$bound;

 

$file = file_get_contents($upload_path . "$imgname." . $pathinfo['extension']);

 

$message .= "Content-Type: image/jpg; name=\"$imgname." . $pathinfo['extension'] . "\r\n"

."Content-Transfer-Encoding: base64\r\n"

."Content-disposition: attachment; file=\"$imgname." . $pathinfo['extension'] . "\r\n"

."\r\n"

.chunk_split(base64_encode($file))

.$bound_last;

if(mail($to, $subject, $message, $headers))

{

    echo 'MAIL SENT';

} else {

    echo 'MAIL FAILED';

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.