...

View Full Version : upload gif's jpg's and email



eyespike1
04-18-2004, 12:07 AM
I have this code which works great for gif's...but it crashes on the jpeg image upload...Please Help!

<?php
// Check to see if the form has been posted
if (isset($_POST['SendFile']))
{
// Set the Array of acceptable FileTypes
$FileTypes=array("image/jpeg", "image/gif");
// Check to ensure the uploaded file is of correct type
if (in_array($_FILES['UPLDoc']['type'],$FileTypes))
{
// Set the upload directory
$UploadDir = 'upload/';
// Move the file
move_uploaded_file($_FILES['UPLDoc']['tmp_name'], $UploadDir . $_FILES['UPLDoc']['name']);
// Open the file and read the contents into a string
$FileName=$UploadDir.$_FILES['UPLDoc']['name'];
$FilePointer=fopen($FileName, "r");
$File=fread($FilePointer, filesize ($FileName));
fclose($FilePointer);
// Encode and chunk split the data for the e-mail
$File=chunk_split(base64_encode($File));
// Set the receiving e-mail address
$EMail="email@email.com";
// Set the headers of the e-mail
$Headers="From: someone@domain.com\n";
$Headers.="Reply-To: someone@domain.com\n";
$Headers.="MIME-Version: 1.0\n";
$Headers.="Content-Type: multipart/mixed; boundary=\"MIME_BOUNDRY\"\n";
$Headers.="X-Sender: someone@domain.com\n";
$Headers.="X-Mailer: PHP4\n";
$Headers.="X-Priority: 3\n";
$Headers.="Return-Path: someone@domain.com\n";
$Headers.="This is a multi-part Contentin MIME format.\n";
// Set the Content of the e-mail
$Content="--MIME_BOUNDRY\n";
$Content.="Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$Content.="Content-Transfer-Encoding: quoted-printable\n";
$Content.="\n";
$Content.="".$_POST['Name']." just sent you the attached file for review.\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY\n";
$Content.="Content-Type: ".$_FILES['UPLDoc']['type']."; name=\"".$_FILES['UPLDoc']['name']."\"\n";
$Content.="Content-disposition: attachment\n";
$Content.="Content-Transfer-Encoding: base64\n";
$Content.="\n";
$Content.="$File\n";
$Content.="\n";
$Content.="--MIME_BOUNDRY--\n";
// Set the Subject of the e-mail
$Subject="New file to review";
// Send the e-mail
mail($EMail,$Subject,$Content,$Headers);
}else
{
echo "You cannot upload this type of file";
}
}
?>
<FORM ENCTYPE="multipart/form-data" METHOD="POST" ACTION="<?=$_SERVER['PHP_SELF'];?>">
<INPUT TYPE="HIDDEN" NAME="SendFile" VALUE="Send File">
<INPUT TYPE="HIDDEN" NAME="MAX_FILE_SIZE" VALUE="100000">
Your Name: <INPUT TYPE="TEXT" NAME="Name"><BR>
Select Document: <INPUT TYPE="FILE" NAME="UPLDoc"><BR>
<INPUT TYPE="SUBMIT" NAME="SendFile" VALUE="Send File">
</FORM>

firepages
04-18-2004, 02:45 PM
you say crash ? you mean its gives an error ? returns a 500 ? simply does not work ? please exapnd

eyespike1
04-19-2004, 02:56 PM
Hi,
After entering in a name in the name field and selecting a .jpg image, the script returns "You cannot upload this type of file"

so actually, the script does not crash, but it will not allow me to upload jpg files...
I hope that helps more

Thanks!

raf
04-19-2004, 03:15 PM
so this


$FileTypes=array("image/jpeg", "image/gif");
// Check to ensure the uploaded file is of correct type
if (in_array($_FILES['UPLDoc']['type'],$FileTypes))
{

returns false.
Your next step would then be to check what the value of $_FILES['UPLDoc']['type'] is. (which will probably be different from "image/jpeg")
So put this on top of your page

print_r($_FILES);

and look what the value for 'type' is.

eyespike1
04-19-2004, 08:19 PM
Thanks!

I placed the code at the top of the page...This is what it returned...

Array ( [UPLDoc] => Array ( [name] => hunt-shirt copy2.jpg [type] => image/pjpeg [tmp_name] => /var/tmp/phpH6ay93 [error] => 0 [size] => 62217 ) ) You cannot upload this type of file

so i changed the file type to pjgeg and Vamoos!

Thanks so much!

seth

bcarl314
04-19-2004, 08:40 PM
FYI,

I've run into this a few times with jpeg files. It seems there is no single use for the mime type and any of the following may apply to jpeg files:

image/jpeg //normal
image/jpg //quite rare
image/pjpeg //a photoshop generated jpeg (from what I can tell)

raf
04-20-2004, 12:19 AM
You're welcome

==> you don't need to change the type, you need to add it to the array, which should now look like

$FileTypes=array("image/jpeg", "image/jpg", "image/pjpeg" , "image/gif");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum