Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2004
    Location
    Atlanta, GA
    Posts
    541

    Need help fixing this conversion

    the problem i'm having is, i'm not getting any errors. But, it's not doing what its suppose to do, which is detect if the image is .gif and if it is convert it to .jpg and save the file with the new .jpg extension.
    is it okay to use $_FILES["Filedata"]["tmp_name"] . jpg for the imagejpeg line at the bottom for saving?

    PHP Code:
    <?php

        
    // Get the session Id passed from Upload.
        
    if (isset($_POST["PHPSESSID"])) {
            
    session_id($_POST["PHPSESSID"]);
        }

        
    session_start();

        
    // Check the upload
        
    if (!isset($_FILES["Filedata"]) || !is_uploaded_file($_FILES["Filedata"]["tmp_name"]) || $_FILES["Filedata"]["error"] != 0) {
            
    header("HTTP/1.1 500 Internal Server Error");
            echo 
    "invalid upload";
            exit(
    0);
        }


    // Get File Extension
    preg_match('/\.([^\.]+)$/',$_FILES["Filedata"]["tmp_name"],$out);
    $ext $out[1];  

    // Convert Image to .jpg 
    if($ext == "jpg" || $ext == "jpeg" || $ext == "pjpeg") {
              
    $image imagecreatefromjpeg($picture); 
                } elseif(
    $ext == "gif") {
              
    $image imagecreatefromgif($picture); 
    }

    //Save converted image
    header ("Content-type : image/jpg");
    ImageJpeg($image);
    ImageJpeg($image"image.jpg");  ///////////// this needs to be $_FILES["Filedata"]["tmp_name"] . jpg
    ImageDestroy($image);

  2. #2
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    wouldn't it be better that you use $_FILES["Filedata"]["type"] to know the image type???

  3. #3
    yeah, i think using the type header of the image would be better.

    using the code you have, maybe try to get it to out put the extension once you've figured it out and then work out where the problem is.

  4. #4
    Join Date
    Apr 2004
    Location
    Atlanta, GA
    Posts
    541
    Quote Originally Posted by Codebird View Post
    wouldn't it be better that you use $_FILES["Filedata"]["type"] to know the image type???
    can you help me recode it correctly, i'm willing to pay $40 via paypal

  5. #5
    Join Date
    Dec 2007
    Location
    Lebanon
    Posts
    413
    Quote Originally Posted by acctman View Post
    can you help me recode it correctly, i'm willing to pay $40 via paypal


    Sent you a pm

Posting Permissions

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