SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Half Moon Bay, CA
    Posts
    118
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_FILES['fileatt']['type']

    Hey All,

    I'm working on an information request form. Part of the form allows users to upload an image that is attached to an email that is generated. The form works great and handles the attachement fine, however, if I try to limit the attached file types as only .jpg or .gif, I cannot get it to work.

    The suspect code is as follows:

    PHP Code:
    if (is_uploaded_file($_FILES['fileatt']['tmp_name'])) {
                        
                            
    $to "Stokes Signs<kai@parishmedia.com>";
                            
    $from "$name<$email>";
                            
    $subject "Information Request From Stokes Web Site";
                            
                            
    // Obtain file upload vars
                            
    $fileatt      $_FILES['fileatt']['tmp_name'];
                            
    $fileatt_type $_FILES['fileatt']['type'];
                            
    $fileatt_name $_FILES['fileatt']['name'];
                            
                            
    $headers "From: $from";
                        
                            if (
    $_FILES['fileatt']['type'] != "image/jpg" && $_FILES['fileatt']['type'] ! = "image/gif"
                            { 
                                echo 
    "This File must be a .jpg or .gif image."
                                exit; 
                            } 
                            else {
                                
    $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}\"";
                                            
                                
    $message "This is a multi-part message in MIME format.\n\n" .
                                           
    "--{$mime_boundary}\n" .
                                           
    "Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
                                           
    "Content-Transfer-Encoding: 7bit\n\n" .
                                           
    $msg "\n\n";
                                
                                
    $data chunk_split(base64_encode($data));
                                
                                
    $message .= "--{$mime_boundary}\n" .
                                            
    "Content-Type: {$fileatt_type};\n" .
                                            
    " name=\"{$fileatt_name}\"\n" .
                                            
    "Content-Disposition: attachment;\n" .
                                            
    " filename=\"{$fileatt_name}\"\n" .
                                            
    "Content-Transfer-Encoding: base64\n\n" .
                                            
    $data "\n\n" .
                                            
    "--{$mime_boundary}--\n";
                            }
                        
                                
    $ok = @mail($to$subject$message$headers);
                                if (
    $ok) {
                                    echo 
    "<p>Mail sent! Yay PHP!</p>";
                                } else {
                                    echo 
    "<p>Mail could not be sent. Sorry!</p>";
                                }
                        } 
    The problem I'm getting is the script always returns

    This File must be a .jpg or .gif image.
    This is the error message I have set if the script detects that the uploade file is not a jpg or a gif. However, the files I am testing are definitely in proper format.

    Can anyone spot my problem?

    Thanks

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2002
    Location
    Toronto, ON
    Posts
    95
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are three jpeg filetypes: 'image/jpeg', 'image/jpg', and 'image/pjpeg'. Try checking those in your code too, it just might work!

    Good Luck,
    Matthew


Bookmarks

Posting Permissions

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