PHP - Mime Type Not Always Recognizing Pdf
Similar TutorialsProbably a stupid question . . .
The MIME type in my php.ini file is set to text/html:
default_mimetype = "text/html"But, because I use XHTML 1.0 Strict, the MIME type of my web pages is set to text/xml: <meta http-equiv="content-type" content="text/xml; charset=utf-8" />I should therefore change the php.ini MIME type to text/xml, right? Can someone help me understand what this type of php is... classes etc..
<?php // item 1 ***** get the excerpt ***** $excerpt = IDX_Plus::get_data('excerpt'); echo "echo-1 excerpt = $excerpt<br><br>"; // item 2 ***** set the excerpt *********** IDX_Plus::set_data( 'excerpt', $excerpt); // item 3 ***** get the excerpt again ******* $excerpt = IDX_Plus::get_data('excerpt'); echo "echo-2 excerpt = $excerpt<br><br>"; // &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& // item 4 now shorten the excerpt // ***** shorten the excerpt *********** $short_excerpt = wp_trim_words($excerpt,10); echo "echo-3 short_excerpt = $short_excerpt<br><br>"; // item 5 ***** set short_excerpt *********** IDX_Plus::set_data( 'short_excerpt', $short_excerpt); // item 6 ***** get short_excerpt again ******* $short_excerpt = IDX_Plus::get_data('short_excerpt'); echo "echo-4 short_excerpt = $short_excerpt<br><br>"; ?>I can't get it to work so if someone can point me to where I can find info on how this type of php works I will be forever grateful...it pulls data form a cache storage on the web and tries to shorten the output and write the short line back to a new variable..The results look like below: Resulting output: ***************** echo-1 excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and bright, this 'one owner' home boasts original hardwood floors and 'classic' 1953 tile in kitchen and bath. The freshly painted interior, new kitchen and bathroom faucets, new vinyl floor in bath, and new water heater, make this home move-in ready. Large 'pool size' fenced yard for the kids. Perfect for your buyers who love the classic look of the 50's, or for those looking to remodel and expand. echo-2 excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and bright, this 'one owner' home boasts original hardwood floors and 'classic' 1953 tile in kitchen and bath. The freshly painted interior, new kitchen and bathroom faucets, new vinyl floor in bath, and new water heater, make this home move-in ready. Large 'pool size' fenced yard for the kids. Perfect for your buyers who love the classic look of the 50's, or for those looking to remodel and expand. echo-3 short_excerpt = Wonderful family home in desirable South Torrance neighborhood. Light and… echo-4 short_excerpt = the short line does not appear so it must not have saved... Is it not possible to get the mime type for a file uploaded using php? Am I going to be forced to use Pear? Php can read the mime type from an image, so why not from any file?? Hello, i have an upload form witch i cannot upload pdf it does not recognize the mine pdf type, any help please. here is the code $target_path = $_SERVER['DOCUMENT_ROOT'] . '/admin/upload/'; $target = "upload/".$HTTP_POST_FILES['uploadedfile']['name']; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $fileSize = $_FILES['uploadedfile']['size']; $fileType = $_FILES['uploadedfile']['type']; if ($_FILES['uploadedfile']['size'] > 0) { if (($_FILES["uploadedfile"]["type"] == "image/gif") || ($_FILES["uploadedfile"]["type"] == "image/jpeg") || ($_FILES["uploadedfile"]["type"] == "image/png" ) || ($_FILES["uploadedfile"]["type"] == "application/msword" ) || ($_FILES["uploadedfile"]["type"] == "application/pdf" ) && ($_FILES["uploadedfile"]["size"] < 512000)) { move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path); $query_upload="INSERT INTO upload (upload, chair, id_domeniu, email_1) VALUES ('" . $target . $_FILES['uploadedfile']['name'] . "', '3', '$id_domeniu', '".$_GET['email_1']."')"; $query_upload="UPDATE domenii SET upload='" . $target . $_FILES['uploadedfile']['name'] . "' WHERE email_1='".$email_1."'"; mysql_query($query_upload) or die(mysql_error()); } else { echo "<script language='javascript'>alert('Programul uploadat trebuie sa fie PDF, DOC, JPEG si mai mic de 500 kilobytes.');window.location = 'javascript:history.go(-1)';</script >"; exit(); } } Hi, I want to recognize let s say "..." in a text. How can that be accomplished in php? And maybe put all "..." into an array. Anybody have any idea how this can be done? Thank you Hi, My results were fine when displaying them on the browser but then want to output student's grades depending on what mark they have got. I have put an if statement for this: Code: [Select] if ($markGrade >= 70){ $grade = "A";} But when I put the above if statement in the code then the browser outputs this: Your Search: Student Username: 'u0867587' Notice: Undefined variable: sessionData in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 79 Notice: Undefined variable: moduleID in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91 Notice: Undefined variable: moduleName in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91 Notice: Undefined variable: markTotal in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91 Notice: Undefined variable: markGrade in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91 Notice: Undefined variable: grade in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 91 Notice: Undefined variable: sessionsHTML in /web/stud/u0867587/Mobile_app/student_overall_grade.php on line 93 Why is it not recognisiong any variables? The code is below and in the attached file. Code: [Select] <?php if (isset($_POST['submit'])) { $query = " SELECT st.CourseId, c.CourseName, st.Year, st.StudentUsername, st.StudentForename, st.StudentSurname, s.ModuleId, m.ModuleName, m.Credits, s.SessionId, s.SessionWeight, gr.Mark, gr.Grade FROM Course c INNER JOIN Student st ON c.CourseId = st.CourseId JOIN Grade_Report gr ON st.StudentId = gr.StudentId JOIN Session s ON gr.SessionId = s.SessionId JOIN Module m ON s.ModuleId = m.ModuleId WHERE (st.StudentUsername = '".mysql_real_escape_string($studentid)."') ORDER BY c.CourseName, st.StudentUsername, m.ModuleName, s.SessionId "; $num = mysql_num_rows($result = mysql_query($query)); mysql_close(); ?> <p> Your Search: </p> <p> <strong>Student Username:</strong> <?php echo "'$studentid'"; ?><br/> </p> <?php if($num ==0){ echo "<p>Sorry, No Records were found from this Search</p>";} else{ function outputModule($moduleID, $moduleName, $sessionData) { if(!count($sessionData)) { return false; } $markTotal = 0; $markGrade = 0; $weightSession = 0; $grade = ""; $sessionsHTML = ''; }; foreach($sessionData as $session) { $sessionsHTML .= "<p><strong>Session:</strong> {$session['SessionId']} {$session['Mark']} {$session['SessionWeight']}%</p>\n"; $markTotal += ($session['Mark'] / 100 * $session['SessionWeight']); $weightSession += ($session['SessionWeight']); $markGrade = ($markTotal / $weightSession * 100); if ($markGrade >= 70){ $grade = "A";} } $moduleHTML = "<p><br><strong>Module:</strong> {$moduleID} - {$moduleName} {$markTotal} {$markGrade} {$grade}</p>\n"; return $moduleHTML . $sessionsHTML; } $output = ""; $studentId = false; $courseId = false; $moduleId = false; while ($row = mysql_fetch_array($result)) { if($studentId != $row['StudentUsername']) { //Student has changed $studentId = $row['StudentUsername']; $output .= "<p><strong>Student:</strong> {$row['StudentForename']} {$row['StudentSurname']} ({$row['StudentUsername']})\n"; } if($courseId != $row['CourseId']) { //Course has changed $courseId = $row['CourseId']; $output .= "<br><strong>Course:</strong> {$row['CourseId']} - {$row['CourseName']} <br><strong>Year:</strong> {$row['Year']}</p>\n"; } if($moduleId != $row['ModuleId']) { //Module has changed if(isset($sessionsAry)) //Don't run function for first record { //Get output for last module and sessions $output .= outputModule($moduleId, $moduleName, $sessionsAry); } //Reset sessions data array and Set values for new module $sessionsAry = array(); $moduleId = $row['ModuleId']; $moduleName = $row['ModuleName']; } //Add session data to array for current module $sessionsAry[] = array('SessionId'=>$row['SessionId'], 'Mark'=>$row['Mark'], 'SessionWeight'=>$row['SessionWeight']); } //Get output for last module $output .= outputModule($moduleId, $moduleName, $sessionsAry); //Display the output echo $output; } ?> [attachment deleted by admin] Hello everyone, I have a website where users are able to send and receive messages. I am trying to devise a way that I can prevent abusive messages from being sent. The best way that I can think of to do this is to use a few key words that would likely be used in an abusive message (basically, any curse word). Does anyone have any ideas on how I can check the text before it is sent for certain key words? Thanks in advance for any help or ideas. Hi all I am having a problem with an error message firing all the time? Code: [Select] if ((($_FILES["file"]["type"] != "application/zip")) || (($_FILES["file"]["type"] != "application/x-zip-compressed")) || (($_FILES["file"]["type"] != "application/x-zip"))) { header('Location: scontrol.php?alert=notzip'); } This is firing when I try uploading a zip, I have 2 questions, have I missed a MIME type (using Chrome) and is a Winrar ZIP different from a standard zip (its not a .rar file!) Thanks hi there, i am fairly new to OOPs in php, i get an error when i declare the argument type (as object) in a function and pass the same type (object). class eBlast { public static function getEmail(object $result) { return $result->email; } } $r = mysql_fetch_object($query); eBlast::getEmail($r); echo gettype($r); // outputs: object error is : Code: [Select] Catchable fatal error: Argument 1 passed to eBlast::getEmail() must be an instance of object, instance of stdClass given, called in C:\wamp\www\integra\client\pl_eblast\admin\send_emails.php on line 145 and defined in C:\wamp\www\integra\client\pl_eblast\app\app.eBlast.php on line 8 if i remove the type declaration in the function it works, but just would like to know why it shows error when pass the same type, also isnt mysql_fetch_object is the instance of stdclass? thanks in advance! I sent an MIME email to an outlook account using Mail() and the HTML part was placed as an attachment for some reason. I dont get caught by most spam filters (just outlook and my school) but I wanted to get this worked out so I dont get caught by any spam filters. Can someone please take a look at my email system below and let me know if everything looks correct? Just in case you need this; I am using PostFix, Zimbra, running on Debian 6.0 (php5) //add From: header $headers = 'From:' . $from . "\n"; $headers .= 'Reply-To:' . $from . "\n"; $headers .= 'Return-Path:' . $from . "\n"; //specify MIME version 1.0 $headers .= "MIME-Version: 1.0\n"; //unique boundary $boundary = uniqid("market"); //tell e-mail client this e-mail contains//alternate versions $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; //plain text version of message $body = "--$boundary\r\n" . "Content-Type: text/plain; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; //adds the remove to the string $body .= chunk_split(base64_encode($plaintxt)); //HTML version of message $body .= "--$boundary\r\n" . "Content-Type: text/html; charset=ISO-8859-1\r\n" . "Content-Transfer-Encoding: base64\r\n\r\n"; $body .= chunk_split(base64_encode($htmltxt)); $message = stripcslashes($body); $subject = stripcslashes($subject); mail($to1[$i], $subject, $message, $headers, "-f $from"); hi all new to php and having a sturggle with email.
I have a a form that when completed I wish to auto email the results to a new member simple enough . i also create a image with their unique name and member type and attach this to the email. I can attach the image and send an html email however I wish to send a plain text email along with this.
here lies the problem.
$to = $email ; $subject = 'some subject'; $bound_text = "010103689954"; $bound = "--".$bound_text."\r\n"; $bound_last = "--".$bound_text."--\r\n"; $headers = "From: <snip email removed>\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; /*HTML part of email*/ $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n"; $message .="Content-Transfer-Encoding: 7bit\r\n\r\n"; $message .='<html><b>html version</b></html>\r\n' .$bound; /*Plain Text part of email*/ $message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"; $message .="Plain text version\r\n" .$bound; /*Attachment part of the email adds jpeg memebrship card*/ $file = file_get_contents("create_membership_card.php?forename=$Forename&surname=$Surname&membership=$Membership"); $message .= "Content-Type: image/jpg; name=\"YourMembershipCard.jpg\"\r\n" ."Content-Transfer-Encoding: base64\r\n" ."Content-disposition: attachment; file=\"YourMembershipCard.jpg\"\r\n" ."\r\n" .chunk_split(base64_encode($file)) .$bound_last; mail($to, $subject, $message, $headers)This will send email in html and attach image but I can not get it to also send the plain/test version. example page to enter email and see what is sent http://www.hexhamcan....php?page=Email Any help with this would be great thanks in advance hope I have provided enough information Lee ps. great place you have here Edited by mac_gyver, 29 May 2014 - 07:26 PM. removed email address I recently changed something in an old script of mine and it doesn't work properly anymore. I don't know what I did, and I don't have a backup, oops! The code below is supposed to take inputs from a web form and turn them into an e-postcard, attaching and sending it as a jpeg on an email, ideally to be displayed inline. $name = $_POST['sendername']; $to = $_POST['recipient']; $from = $_POST['senderemail']; $subject = basename( $name)." has sent you a jCard!"; $message = $_POST['text']; $bcc = $_POST['bcc']; $finalimage = $_POST['finalimage']; //create a boundary string. It must be unique //so we use the MD5 algorithm to generate a random hash $random_hash = md5(date('r', time())); //define the headers we want passed. Note that they are separated with rn $headers = "From: ".$name." <".$from.">\r\nReply-To: ".$name." <".$from.">\r\nBcc: ".$bcc."\r\nX-Mailer: PHP/".phpversion();""; //add boundary string and mime type specification $headers .= "\r\nContent-Type: multipart/mixed; boundary='PHP-mixed-".$random_hash."'"; //read the attachment file contents into a string, //encode it with MIME base64, //and split it into smaller chunks $attachment = chunk_split(base64_encode(file_get_contents($finalimage))); //define the body of the message. ob_start(); //Turn on output buffering ?> --PHP-mixed-<?php echo $random_hash; ?> Content-Type: multipart/alternative; boundary='PHP-alt-<?php echo $random_hash; ?>' --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/plain; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit <?php echo $name; ?> sent you a jCard, click the attachment to view it. Send your own jCards at www.j-cards.co.uk! --PHP-alt-<?php echo $random_hash; ?> Content-Type: text/html; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit <p><?php echo $name; ?> sent you this jCard:</p> <img src="cid:<?php echo $random_hash; ?>.jCard.jpg" /> <p>Send your own jCards at <a href="http://www.j-cards.co.uk">j-cards.co.uk</a>!</p> --PHP-alt-<?php echo $random_hash; ?>-- --PHP-mixed-<?php echo $random_hash; ?> Content-Type: image/jpeg; name='jCard.jpg' Content-Transfer-Encoding: base64 Content-ID: <<?php echo $random_hash; ?>.jCard.jpg> Content-Disposition: attachment; filename='/jCard.jpg' <?php echo $attachment; ?> --PHP-mixed-<?php echo $random_hash; ?>-- <?php //copy current buffer contents into $message variable and delete current output buffer $message = ob_get_clean(); //send the email $mail_sent = @mail( $to, $subject, $message, $headers ); //if the message is sent successfully return success page html. Otherwise return send fail html. echo $mail_sent ? "<html> snip... The email gets sent, and the source of the email looks identical to that of previous correctly displayed versions, but for some reason the email reader no longer renders the html, instead it just shows plain text, so it looks like the source just without headers - e.g.: Quote From: whoever@wherever.com To: friend@bestfriend.com --PHP-mixed-643f51499c414383c5735473100462e4 Content-Type: multipart/alternative; boundary='PHP-alt-643f51499c414383c5735473100462e4' --PHP-alt-643f51499c414383c5735473100462e4 Content-Type: text/plain; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit Joe sent you a jCard, click the attachment to view it. Send your own jCards at www.j-cards.co.uk! --PHP-alt-643f51499c414383c5735473100462e4 Content-Type: text/html; charset='iso-8859-1'; Content-Transfer-Encoding: 7bit <p>Joe sent you this jCard:</p> <img src="cid:643f51499c414383c5735473100462e4.jCard.jpg" /> <p>Send your own jCards at <a href="http://www.j-cards.co.uk">j-cards.co.uk</a>!</p> --PHP-alt-643f51499c414383c5735473100462e4-- --PHP-mixed-643f51499c414383c5735473100462e4 Content-Type: image/jpeg; name='jCard.jpg' Content-Transfer-Encoding: base64 Content-ID: <643f51499c414383c5735473100462e4.jCard.jpg> Content-Disposition: attachment; filename='/jCard.jpg' /9j/4AAQSkZJRgABAQA... (base64 characters - very long - snipped) --PHP-mixed-643f51499c414383c5735473100462e4-- So everything is being sent, it's just an issue of getting it read correctly by the email program (worked before in gmail and hotmail). So I think it's an issue with the headers or boundary string I'm using, but they look alright to me, I just can't see what I've done wrong. Any ideas? I have a scenario where users are downloading files from a legacy system and uploading the files into a new system that I am supporting. Many of the files do not have an extension (most are tiffs).
The issue we have is that the new system doesn't know how to open these files (we have them open in a preview window in the new system). I have tried numerous solutions, including finfo_file() and the depreciated mime_content_type() funcitons), but all they seem to return is "application/octet-stream".
Thanks.
Hey guys, Go easy on me, I'm not a large PHP coder at all however here is the issue I am having. I have acquired a wordpress plugin from a guy to deal with ticketing. From this plugin I am sending out a Mime multipart message with both HTML and plain text code. Here's the thing: If I send this out via gmail's SMTP server the message appears perfectly, however if I send it out via pro.turbo-smtp.com it arrives as an attachment due to the fact that in transit it seems to have lost it's Mime-Version: and Content-type: headers such as displayed below: Date: Fri, 19 Dec 2014 16:02:28 +0000 Return-Path: <REMOVEDADDRESS> To: REMOVEDADDRESS From: Name Here <REMOVEDADDRESS> Reply-To: Subject: Booking Confirmation Message-ID: <edc5de8156becec1bf53e402b25c9b93@REMOVED.co.uk> X-Priority: 3 X-Mailer: PHPMailer 5.2.7 (https://github.com/PHPMailer/PHPMailer/) MIME-Version: Content-Type: Content-Transfer-Encoding: 8bit --Part_A_aaa4586399e49459e0dce4368165275f Hey Mr A Sample, Thank you for booking with us.I am more than positive that this is not a PHP issue due to it appearing fine via google's SMTP server, but I am just wondering if anyone has ever came across such a thing and if anyone can shed any light? If anyone wants the PHP code I'm sure I can supply. Many thanks in advance!, Chris I have a strange problem. When a guest visits my contact-user.php page, they get a message telling them the must login before viewing the page. After the guest logs in, they view the same page and it tells them they have to login again (keeps on looping). But if they manually refresh that page with the "you must be logged in" message, it recognizes the login and lets them in. How can I get this page to immediately recognize that the user is logged in and not require them to refresh the page manually? Here is my code for contact-user.php <?php session_start(); header("Cache-Control: private, max-age=10800, pre-check=10800"); header("Pragma: private"); header("Expires: " . date(DATE_RFC822,strtotime("+2 day"))); include("connection.php"); mysql_select_db("database"); if (isset($_SESSION['username'])) { ******** MY HTML PAGE CONTENT ******** } else { echo "<meta http-equiv='REFRESH' content='2;url=http://www.mysite.com/login.php'> <center><font color='#EE0000'><p>You must be logged in before negotiating. You will now be redirect to the login page.</p></font></center>"; } ?> Here is my code for login.php script: <?php include("connection.php"); mysql_select_db("database"); session_start(); if(isset($_POST['login'])){ $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $tUnixTime = time(); $sGMTMySqlString = gmdate("Y-m-d H:i:s", $tUnixTime); if (!$username || !$password) { print "Please fill out all fields."; exit; } $logres = mysql_num_rows(mysql_query("SELECT * FROM members WHERE username = '$username' and password = '$password'")); if ($logres <= 0) { print "Login failed. If you have not already, please signup. Otherwise, check your spelling and login again."; exit; } else { $_SESSION['username'] = $username; if (isset($_SESSION)) { echo'You are now logging in'; mysql_query("UPDATE members SET activity = '$sGMTMySqlString' WHERE username = '$username'"); } else { echo "You are not logged in!"; } echo'<html><head><meta http-equiv="REFRESH" content="1;url=http://www.mysite.com/members/' . $_SESSION['username'] . '/"></head><body></body></html>'; exit; } } ?> I'm working on a two-file upload form and want to be able to check the mime types of two filenames in a string variable.
The code below was working when the variable @resume_path contained just one filename. How can I modify this to accommodate two files?
when I echo $resume_path, I get, for example: cover_letter_centerline.doc, cover_letter_ctg.doc
Thanks!
//DO NOT TRUST $_FILES['upfile']['mime'] VALUE !! //Check MIME Type by yourself. $finfo = new finfo(FILEINFO_MIME_TYPE); if (false === $ext = array_search( $finfo->file($_FILES['resume_path']['tmp_name']), array( 'txt' => 'text/plain', 'doc' => 'application/msword', 'pdf' => 'application/pdf', ), true )) { throw new RuntimeException('Invalid file format.'); } echo "Sorry, invalid file format. Please try again."; echo $ext; Hey Guys, How are custom Mime Types achieved? Had a quick search through the forums, and most of the posts relate to mail() questions. Did a google search and found a completely useless article that told me to edit a non-existent text box. Quick example, the file type I want is .WAgame, I got this far before I realised what I was doing didn't make sense. So I looked up mime types, knowing that this file would not exist. if ($_FILES["file"]["type"] != "file/WAgame") { naughty! } Help! Edit: Thanks in advance for any help you can provide on this. Bob G. BACKGROUND: I have an app that is hosted on Host Monster and its script includes a Class that is supposed to send MIME emails with or without attachments using only MIME types text, html, and image. It was working fine. I hadn't worked with or on it for about two months then found, last week, that it would no longer send emails even though the script runs without any Warnings. I've worked on this for several days now and I'm stuck. EXPECTED BEHAVIOR: When the script runs, it should send a simple text only email to a given email address and an more complex email that requires html and an in-line image in the body and an attachment with the same image. The image type is jpeg. ACTUAL BEHAVIOR: The script runs to completion with no Warning but sends neither of the two emails. CODE: Attached and cc'd below is a script which mimics the code in my app and the actual behavior described above but only for the simple email mentioned above. To simplify debug I've commented out that part of the script that should send out the more complex email mentioned above. Note: You can run the script by going to http://www.unitresearch03.com/Admin/SendUserEmailHM01.php Note: Line 6 can be changed to your own email address for testing BEGIN CODE: Code: [Select] <?php //TOP LINE CODE ////SIMPLE MIME EMAIL CODE - NO ATTACHMENTS ////////////////////////////////////////////// $mail = new mime_mail ; $mail->from = "ragsr@ix.netcom.com" ; $mail->to = "ragsr@ix.netcom.com" ; $mail->subject = "SIMPLE MIME EMAIL - NO ATTACHMENTS" ; $mail->body = "SIMPLE MIME EMAIL BODY" ; $mail->send() ; ////END OF SIMPLE MIME EMAIL CODE //////////////////////////////////////////////////////// ////START MIME EMAIL CODE - ALLOWS ATTACHEMENTS ///////////////////////////////////////////////// //SIMPLE SEND EMAIL PG.448 PHP REFERENCE PLUS ATTACHMENT EXAMPLE FROM SAME PAGE //include "mime_mail.inc"; //THIS CAUSED A WARNING AND, APPARENTLY, IS NOT REQUIRED. CODE OK W/O IT //READ FILE $filename="/home1/unitcons/public_html/unitresearch03/TCStripComposition-27Cb.jpg" ; $content_type="image/jpeg" ; //OPEN, EXTRACT DATA, THEN CLOSE FILE $fd=fopen($filename, "r") ; $data=fread($fd, filesize($filename)) ; fclose($fd) ; $fileX="/home1/unitcons/public_html/unitresearch03TCStripComposition-27Cb.jpg" ; $ftype=filetype ($filename) ; $fsize=filesize($filename) ; //echo "FILE TYPE :"."$ftype"."<br>" ; //echo "FD FILE TYPE :"."$fdltype"."<br>" ; //echo "DATA :"."$data"." END DATA"."<br>" ; //echo "FSIZE :"."$fsize"."<br>" ; //echo "FDSIZE :"."$fsize"."<br>" ; //echo "FD :"."$fd"."<br>" ; //CREATE OBJECT INSTANCE $mail = new mime_mail ; //SET ALL DATA SLOTS $mail->from = "thromptmweeklycs@unitresearch03.com" ; $mail->to = "ragsr@ix.netcom.com" ; $mail->subject = "XXXThrompTM Weekly Comic Strip - Week of 6/20/201" ; $mail->body = "<html>Hope you enjoy your ThrompTM today! <br> <br> <br> <img src=http://www.unitresearch03.com/TCStripComposition-27Cb.jpg height='197' width='500' > </html>"; //DEFINE ATTACHMENT $name = $fileX ; $message = $data ; //ADD ATTACHEMENT //$mail->add_attachment ($data, $filename, $content_type) ; //SEND EMAIL //$mail->send() ; ////EBD SEND EMAIL WITH ATTACHMENT ////MIME CLASS class mime_mail { var $parts; var $to; var $from; var $headers; var $subject; var $body ; /* * void mime_mail() * class constructor */ function mime_mail () { $this->parts = array() ; $this->to = "" ; $this->from = "" ; $this->subject = "" ; $this->body = "" ; $this->headers = "" ; } /* * void add_attachement (string message, [string name], [string ctype]) * Add an attachment to the mail object */ function add_attachment ($message, $name = "", $ctype = "text/html jpeg" ) //function add_attachment ($data, $fileX, $content_type ) { echo "CTYPE IN AA :"."$ctype"."<br>" ; //echo "MESSAGE IN AA :"."$message"."<br>" ; echo "ENCODE IN AA: "."$encode"."<br>" ; echo "NAME IN AA :"."$name"."<br>" ; //echo "DATA IN AA :"."$data"."<br>" ; $partsd = $this->parts[] = array ( "ctype" => $ctype, "message" => $message, "encode" => $encode, "name" => $name, ); echo ("ARRAY#1 CTYPE :"."$partsd[ctype]"."<br>") ; //echo ("ARRAY#2 MESSAGE :"."$partsd[message]"."<br>") ; echo ("ARRAY#3 ENCODE :"."$partsd[encode]"."<br>") ; echo ("ARRAY#4 NAME :"."$partsd[name]"."<br>") ; //echo ("ARRAY#5 DATA :"."$partsd[data]"."<br>") ; $sizeX=sizeof($this->parts) ; echo "SIZE OF ARRAY IN ADD ATTACHMENT:"."$sizeX"."<br>" ; } /* * void build_message (array part= * Build message parts of an multipart mail */ function build_message ($part ) { $message = $part[ "message"]; //echo "MESSAGE IN BUILD:"."$message"."<br>" ; $message = chunk_split(base64_encode($message)) ; //echo "MESSAGE :"."$message"."<br>" ; $encoding = "base64" ; $partctype = $part["ctype"] ; $partname = $part["name"] ; echo "PART CTYPE :"."$partctype"."<br>" ; echo "PART NAME :"."$partname"."<br>" ; return "Content-Type: ".$part["ctype"]. ($part["name"]?" ; name =\"". $part["name"]. "\"":""). "\nContent-Transfer-Encoding: $encoding\n\n$message\n" ; } /* * void build_multipart() * Build a multipart mail */ function build_multipart() { $boundary = "b".md5(uniqid(time())) ; $multipart = "Content-Type: multipart/mixed; boundary = $boundary\n\nThis is a MIME encoded message.\n\n--$boundary" ; //$sizeX=sizeof($this->parts) ; //echo "SIZE OF ARRAY :"."$sizeX"."<br>" ; for ($i = sizeof($this->parts)-1; $i >= 0; $i--) { $multipart .= "\n".$this->build_message($this->parts[$i])."--$boundary" ; //echo "MULTIPART :"."$multipart"."<br>" ; } return $multipart.= "--\n" ; } /* * string get_mail() * returns the constructed mail */ function get_mail($complete = true) { $complete = true ; echo "COMPLETE :"."$complete"."<br>" ; ////STAEMENT ADDED TO FORCE IF ($COMPLETE) {} BELOW TO RUN //echo "MESSAGE IN GET MAIL:"."$message"."<br>" ; $mime = "" ; if (!empty($this->from)) $mime .= "From: ".$this->from. "\n" ; echo "MIME 1:"."$mime"."<br>"; if (!empty($this->headers)) $mime .= $this->headers. "\n" ; echo "MIME 2:"."$mime"."<br>"; if ($complete) { echo "MIME 3:"."$mime"."<br>"; if (!empty($this->to)) { $mime .= "To: $this->to\n" ; echo "MIME 4:"."$mime"."<br>"; } if (!empty($this->subject)) { $mime .= "Subject: $this->subject\n" ; echo "MIME 5:"."$mime"."<br>"; } } if (!empty($this->body)) $this->add_attachment($this->body, "", "text/html"); echo "MIME 55:"."$mime"."<br>"; $mime .= "MIME-Version: 1.0\n".$this->build_multipart() ; echo "MIME 6:"."$mime"."<br>"; return $mime; } /* * void send() * Send the mail (last class-function to be called) */ //function send ($message, $data, $fileX, $content_type) function send () { //$bodyY=$this->body ; //echo "BODYY :"."$bodyY"."<br>" ; $mime=$this->get_mail () ; echo "MIME 7:"."$mime"."<br>" ; mail($this->to, $this->subject, "" , $mime) ; //mail($this->to, $this->subject, $this->body, $mime) ; } } ; ////END OF MIME CLASS CODE ///////////////////////////////////////////////////////////////// ?>END CODE: Hello,
I'm having a huge issue right now decoding a zip file from an attachment with a content-encoding of quoted-printable. I have tried a couple different methods (such as decoding the entire attachment or decoding it line by line), but none have produced a valid file when saved. What I don't understand is that I can download and open the file in Outlook fine, so there must be something wrong with the decoder. Here is a code snippet of my recent attempt:
elseif ($transferEncoding == 'quoted-printable'){ $fileError = true; $attachmentParts = explode("\n", $currentPart->getContent()); $attachmentArray = array(); foreach ($attachmentParts as $line){ array_push($attachmentArray, quoted_printable_decode($line)); } $attachment = implode("", $attachmentArray); file_put_contents($unzipPath . '.zip', $attachment); } $unzipper = new Decompress(array( 'adapter' => 'Zip', 'options' => array( 'target' => $unzipPath, ) )); $unzipper->filter($unzipPath . '.zip'); unlink($unzipPath . '.zip');I'm using Zend Framework 2 methods for unzipping the file when it's done, but there is a CRC error because the file is getting corrupted during the decode. This is how the file compares to the original (using Beyond Compare 3): So it is finding the hex for CLRF and removing it from the file. Any ideas on this would be greatly appreciated as I have been trying to solve this for about a month now. Thanks, -mcfloyd |