Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    upload gif's jpg's and email

    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>

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,040
    Thanks
    10
    Thanked 92 Times in 90 Posts
    you say crash ? you mean its gives an error ? returns a 500 ? simply does not work ? please exapnd
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    so this
    PHP Code:
    $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.
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

  • #5
    New to the CF scene
    Join Date
    Apr 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    Mega-ultimate member
    Join Date
    Jun 2002
    Location
    Winona, MN - The land of 10,000 lakes
    Posts
    1,855
    Thanks
    1
    Thanked 45 Times in 42 Posts
    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)

  • #7
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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");
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •