Jump to content

Joob

Members
  • Posts

    3
  • Joined

  • Last visited

Profile Information

  • Gender
    Male
  • Location
    </>
  • Interests
    JavaScript, PHP

Joob's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. I've been looking, and I think it's something more like this .. How can I implement this code down in my code //------------------------ ATTACHMENTS ------------------------------------// //loop through email parts foreach($decoded[0]['Parts'] as $part){ //check for attachments if($part['FileDisposition'] == 'attachment'){ //format file name (change spaces to underscore then remove anything that isn't a letter, number or underscore) $filename = preg_replace('/[^0-9,a-z,\.,_]*/i','',str_replace(' ','_', $part['FileName'])); //write the data to the file $fp = fopen('save_dir/' . $filename, 'w'); $written = fwrite($fp,$part['Body']); fclose($fp); //add file to attachments array $attachments[] = $part['FileName']; } } //print out the attachments for debug print_r($attachments); What u think.. ?
  2. @justsomeguy thank you for ur reply. The email was supposed to fetch the information from this database table, and save the attachments in the attachment folder. I'm just having trouble with attachments. When clicking on the attachment, the name of the file that was supposed to be sent, "imagen.jpg or mypdf.pdf", appears until then, but when I go to click on the file, to download, the link appears well, but redirects to the initial page and it is only with the link thus "www.site.com/attachment/imagem.jpg, etc ...", that is, it is not receiving the attachments. I was trying to adapt this code (to 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); } } }
  3. Hello, I have a problem with my code.. I cant do download attachments, when I click in attachment "image.jpg", the link appears this way "www.site.com/image.jpg" but the link doesn't existed, and go to automatically to my home page without download the file.. $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("/boundary=\"(.*)\"/", $email_body, $getKey); $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); }else{ $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 .. When I click in attachment and I just wanted that's possible to download the image, pdf, txt, zip, rar, etc.. once they are saved in the attachment folder. I already called the attachment of these two forms, but nothing.. PHP Code: <a target="_blank" href="https://site.com/<?=$attach_name[1][0]?>" data-target="<?=$id?>"><?=$attach_name[1][0]?></a> <a target="_blank" href="data:<?=$attach_type[1][0]?>;base64,<?=$pure_code?>"> <?=$attach_name[1][0]?> </a> I don't know if u understand my problem. Best Regards
×
×
  • Create New...