rachelm Posted November 20, 2008 Share Posted November 20, 2008 I have built a php enquiry form with a file upload feature. Previously, emails have come through this form with jpg attachments appearing normal. The last 2 enquiries have come through with jpgs that appear "blank" even though the filesizes were 57kb and 296kb. I guess they are being corrupted somewhere. I have sent through a couple of tests with jpgs around 91kb and they worked fine... what might be causing some image attachments to fail? Link to comment https://forums.phpfreaks.com/topic/133572-php-file-uploads-blank-jpgs-attached-to-email/ Share on other sites More sharing options...
trq Posted November 20, 2008 Share Posted November 20, 2008 Without seeing code we wouldn't have a clue. Link to comment https://forums.phpfreaks.com/topic/133572-php-file-uploads-blank-jpgs-attached-to-email/#findComment-694770 Share on other sites More sharing options...
elite_prodigy Posted November 20, 2008 Share Posted November 20, 2008 If you are checking for size parameters such as height and width and then denying an upload based on that you might have the problem somewhere within that. Link to comment https://forums.phpfreaks.com/topic/133572-php-file-uploads-blank-jpgs-attached-to-email/#findComment-694772 Share on other sites More sharing options...
rachelm Posted November 20, 2008 Author Share Posted November 20, 2008 The only thing I am checking is filesize, restricting it to 1mb. The HTML is basically: <form action="sendtest.php" method="post" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1048576" /> <input type="file" name="myfile" /> </form> The code in sendtest.php: if($_FILES['myfile']['size'] == 0){ die("Image upload failed. Please try again."); } if($_FILES['myfile']['size'] > 1048576){ die("The uploaded image exceeds maximum file size."); } $to = "[email protected]"; $message = "testing message text"; $fileatt = $_FILES['myfile']['tmp_name']; $fileatttype = "image/jpg"; $fileattname = "project.jpg"; $headers = "From: $email"; $file = fopen( $fileatt, 'rb' ); $data = fread( $file, filesize( $fileatt ) ); fclose( $file ); $semi_rand = md5( time() ); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $whole_message = "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message."\n\n"; $data = chunk_split( base64_encode( $data ) ); $whole_message .= "--{$mime_boundary}\n" . "Content-Type: {$fileatttype};\n" . " name=\"{$fileattname}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileattname}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if( mail( $to, $subject, $whole_message, $headers )) { echo "<p>Thank you for your enquiry.</p>"; } else { echo "<p>There was an error sending the mail.</p>"; } Link to comment https://forums.phpfreaks.com/topic/133572-php-file-uploads-blank-jpgs-attached-to-email/#findComment-694775 Share on other sites More sharing options...
rachelm Posted November 21, 2008 Author Share Posted November 21, 2008 I am wondering if it's a problem with the MIME headers? Link to comment https://forums.phpfreaks.com/topic/133572-php-file-uploads-blank-jpgs-attached-to-email/#findComment-694862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.