Jump to content

Path to Downloading Attachment


Recommended Posts


I have a problem with my code.. I cant do download attachment, when I click on link "image.jpg", the link appears this way "www.site.com/image.jpg" but the link doesnt existe.

$id = $_POST['id'];
$pdo = new PDO("sqlite:mydb.db");
$email = $pdo->query("SELECT * FROM `myemails` WHERE `id`='$myid'")->fetch(PDO::FETCH_ASSOC);

$email_body = base64_decode($email['message']);

$letter_html = "";
//$op_getKey = preg_match_all("/Content-Type: multipart\/alternative; boundary=\"(.*?)\"/", $email_body, $getKey);
//$op_getKey = preg_match_all("/alternative; boundary=\"(.*)\"/", $email_body, $getKey);
$op_getKey = preg_match_all("/boundary=\"(.*)\"/", $email_body, $getKey);
//$has_attachment = preg_match_all("/multipart\/mixed/; boundary=\"(.*?)\"/", $email_body, $attachment);
$has_attachment = preg_match_all("/multipart\/mixed/", $email_body, $attachment);
if ($op_getKey) {
if ($has_attachment) {
$mailParts = explode("--" . $getKey[1][1], $email_body);
$attachParts = explode("--" . $getKey[1][0], $email_body);

$get_attach_name=preg_match_all("/filename=\"(.*?)\"/", $attachParts[2], $attach_name);
$get_attach_type=preg_match_all("/Content-Type: (.*?);/", $attachParts[2], $attach_type);
$pure_code = explode("\n\n",$attachParts[2]);
$pure_code = str_replace("\r","",$pure_code[1]);
$pure_code = str_replace("\n","",$pure_code);
$mailParts = explode("--" . $getKey[1][0], $email_body);

Can you give me some help implementing this code in my code?

$savedir = __DIR__ . '/attachment/';

$myemail = $email->search('ALL');
if ($myemail ) {
rsort($myemail );
foreach ($myemail as $my2email) {
foreach ($my2email->getAttachments() as $attachment) {
$savepath = $savedir . $attachment->getFilename();
file_put_contents($savepath, $attachment);

So that it is possible, whenever you receive an email, that the file go to the "attachment" folder and can download the image or file ..



Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.