PHP swfupload How to create thumbnails and save them to a specified folder

Source: Internet
Author: User
Tags exit count explode file size

 

upload.php   <?php/*  * swfupload picture upload    */      if (Isset ($_post["PHPSESSID"])) {         session_id ($_post["PHPSESSID"]);    }     session_start ();     Ini_set ("Html_errors", "0");     if (!isset ($_files["Filedata"])!is_uploaded_file ($_files["Filedata" ["Tmp_name"]) $_files["Filedata" ["Error"]!= 0 {        echo "Error: Invalid upload!";         exit (0);    } &nbs P    //Get the image and create a thumbnail       $file _types=explode (".", $_files["Filedata"] [nam E "]);       $file _type= $file _types[count ($file _types)-1];     if (Strtolower ($file _type) = = ' gif ')     {        $img = Imagecreatefromgif ($_f iles["Filedata" ["Tmp_name"]);    }     Else if (Strtolower ($file _type) = = ' png ')     {        $img = IM Agecreatefrompng ($_files["Filedata" ["Tmp_name"]);    }     Else if (Strtolower ($file _type) = = ' bmp ')     {        $img = IM Agecreatefromwbmp ($_files["Filedata"] ["tmp_name"]);    }     Else     {        $img = Imagecreatefromjpeg ($_files["Filedat A "[" Tmp_name "]);    }       if (! $img) {        echo "error: Unable to create image". $_files["Filedata" ["Tmp_name"];         exit (0);    }       $width = Imagesx ($img);     $height = Imagesy ($img);       if (! $width! $height) {        echo "Error: Invalid high or High";         Exi T (0);    }      //build the thumbnail     $target _width = 100;     $target _height = 100;     $target _ratio = $target _width/$target _height;       $IMG _ratio = $width/$height;   &NBSP;   if ($target _ratio > $img _ratio) {        $new _height = $target _height;         $new _width = $img _ratio * $target _height;    } else {        $new _height = $target _width/$img _ratio;         $ New_width = $target _width;    }       if ($new _height > $target _height) {        $new _height = $tar Get_height;    }     if ($new _width > $target _width) {        $new _height = $target _width ;    }       $new _img = imagecreatetruecolor (100, 100);     if (! @imagefilledrectangle ($new _img, 0, 0, $target _width-1, $target _height-1, 0)) {//Fill the image Black         echo "Error: Cannot fill new picture";         exit (0);    }       if (! @imagecopyresampled ($new _img, $img, ($target _width-$new _width)/2, ($target _ height-$new _heigHT)/2, 0,0, $new _width, $new _height, $width, $height)) {        echo "Error: Image not resized";     &N Bsp   Exit (0);    }       if (!isset ($_session["File_info")) {        $_session["File_inf O "] = array ();    }     Ob_start ();     imagejpeg ($new _img);     $imagevariable = ob_get_contents ();     Ob_end_clean ();       $file _id = MD5 ($_files["Filedata"] ["tmp_name"] + rand () *100000);       $_session["File_info" [$file _id] = $imagevariable;     echo "Fileid:". $file _id;  //return the file ID to the script     include ("upimg.class.php");     if (!empty ($_files["Filedata"]) and count (Explode (",", $_session["Upload_tem")) <5)     {         $folder = "upload/images/tem/". Date ("y-m-d");         $up = new Upimg ("$folder", "$folder"); Can be written as: $up = new upimg (); &nbsp       $up->autothumb = TRUE; Can omit         $up->srcdel=true;         $up->thumbwidth = 550; can be omitted         $up->thumbheight = 400; Can omit         $up->maxsize=2014; Upload file size Unit is KB         $result = $up->upload (' filedata '); The Name property value of <input/> in HTML         $_session["Upload_tem"]=$_session["Upload_tem"]. ",". $up- >thumbPath;         $_session["Upload_tem"]=trim ($_session["Upload_tem"], ",");      }  ?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.