php SWFUpload 怎麼建立縮圖並且儲存到指定檔案夾裡面

來源:互聯網
上載者:User

 

upload.php <?php/* * swfupload圖片上傳   */     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 "錯誤:無效的上傳!";        exit(0);    }     // Get the image and create a thumbnail     $file_types=explode(".",$_FILES["Filedata"]["name"]);     $file_type=$file_types[count($file_types)-1];    if(strtolower($file_type)=='gif' )    {        $img = imagecreatefromgif($_FILES["Filedata"]["tmp_name"]);    }    else if(strtolower($file_type)=='png')    {        $img = imagecreatefrompng($_FILES["Filedata"]["tmp_name"]);    }    else if(strtolower($file_type)=='bmp')    {        $img = imagecreatefromwbmp($_FILES["Filedata"]["tmp_name"]);    }    else    {        $img = imagecreatefromjpeg($_FILES["Filedata"]["tmp_name"]);    }     if (!$img) {        echo "錯誤:無法建立映像 ". $_FILES["Filedata"]["tmp_name"];        exit(0);    }     $width = imageSX($img);    $height = imageSY($img);     if (!$width !$height) {        echo "錯誤:無效的高或高";        exit(0);    }     // Build the thumbnail    $target_width = 100;    $target_height = 100;    $target_ratio = $target_width / $target_height;     $img_ratio = $width / $height;     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 = $target_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 "錯誤:不能填充新圖片";        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 "錯誤:不能調整大小的映像";        exit(0);    }     if (!isset($_SESSION["file_info"])) {        $_SESSION["file_info"] = 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"); //可以寫成:$up = new upimg();        $up->autoThumb = TRUE; //可省略        $up->srcDel=TRUE;        $up->thumbWidth = 550; //可省略        $up->thumbHeight = 400; //可省略        $up->maxsize=2014; //上傳檔案大小單位是kb        $result= $up->upload('Filedata'); // HTML中<input />的name屬性值        $_SESSION["upload_tem"]=$_SESSION["upload_tem"].",".$up->thumbPath;        $_SESSION["upload_tem"]=trim($_SESSION["upload_tem"],",");     } ?>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.