欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實(shí)現(xiàn)從上傳文件創(chuàng)建縮略圖的方法

 更新時(shí)間:2015年04月02日 11:29:44   作者:不吃皮蛋  
這篇文章主要介紹了php實(shí)現(xiàn)從上傳文件創(chuàng)建縮略圖的方法,涉及php操作上傳文件及圖片操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php實(shí)現(xiàn)從上傳文件創(chuàng)建縮略圖的方法。分享給大家供大家參考。具體實(shí)現(xiàn)方法如下:

<?php
if ($_REQUEST['action']=="add"){
$userfile = $HTTP_POST_FILES['photo']['tmp_name'];
$userfile_name = $HTTP_POST_FILES['photo']['name'];
$userfile_size = $HTTP_POST_FILES['photo']['size'];
$userfile_type = $HTTP_POST_FILES['photo']['type'];
///////////////////////// 
//GET-DECLARE DIMENSIONS //
$dimension = getimagesize($userfile);
$large_width = $dimension[0]; // GET PHOTO WIDTH
$large_height = $dimension[1]; //GET PHOTO HEIGHT
$small_width = 120; // DECLARE THUMB WIDTH
$small_height = 90; // DECLARE THUMB HEIGHT
/////////////////////////
//CHECK SIZE //
if ($userfile_size>102400){
   $error=1;
   $msg = "The photo is over 100kb. Please try again.";
}
////////////////////////////////
// CHECK TYPE (IE AND OTHERS) //
if ($userfile_type="image/pjpeg"){
  if ($userfile_type!="image/jpeg"){
    $error=1;
    $msg = "The photo must be JPG";
  }
}
//////////////////////////////
//CHECK WIDTH/HEIGHT //
if ($large_width!=600 or$large_height!=400){
$error=1;
$msg = "The photo must be 600x400 pixels";
}
///////////////////////////////////////////
//CREATE THUMB / UPLOAD THUMB AND PHOTO ///
if ($error<>1){
  $image = $userfile_name; //if you want to insert it to the database
  $pic = imagecreatefromjpeg($userfile);
  $small = imagecreatetruecolor($small_width,$small_height);
  imagecopyresampled($small,$pic,0,0,0,0, $small_width, $small_height, $large_width, $large_height);
  if (imagejpeg($small,"path/to/folder/to/upload/thumb".$userfile_name, 100)){  
    $large = imagecreatetruecolor($large_width,$large_height);
  imagecopyresampled($large,$pic,0,0,0,0, $large_width, $large_height, $large_width, $large_height);
    if (imagejpeg($large,"path/to/folder/to/upload/photo".$userfile_name, 100))
   {}
      else {$msg="A problem has occured. Please try again."; $error=1;}
  }
  else {
   $msg="A problem has occured. Please try again."; $error=1;
  }
}
//////////////////////////////////////////////
/// If everything went right a photo (600x400) and
/// a thumb(120x90) were uploaded to the given folders
}
?>
<html><head><title>create thumb</title></head>
<body>
<form name="form1" enctype="multipart/form-data" action="thisfile.php?action=add" method="post">
Select Photo: <input type="file" name="photo">
<input type="submit" name="submit" value="CREATE THUMB AND UPLOAD">
</form>
</body
</html>

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • smarty的保留變量問題

    smarty的保留變量問題

    {$smarty}保留變量可以被用于訪問一些特殊的模板變量,以下是全部頁(yè)面請(qǐng)求變量。
    2008-10-10
  • php+websocket 實(shí)現(xiàn)的聊天室功能詳解

    php+websocket 實(shí)現(xiàn)的聊天室功能詳解

    這篇文章主要介紹了php+websocket 實(shí)現(xiàn)的聊天室功能,結(jié)合實(shí)例形式詳細(xì)分析了php+websocket 實(shí)現(xiàn)的聊天室功能相關(guān)配置、實(shí)現(xiàn)方法與操作注意事項(xiàng),需要的朋友可以參考下
    2020-05-05
  • php socket通信(tcp/udp)實(shí)例分析

    php socket通信(tcp/udp)實(shí)例分析

    這篇文章主要介紹了php socket通信(tcp/udp)方法,結(jié)合實(shí)例形式分析了基于socket實(shí)現(xiàn)tcp與udp通信的相關(guān)技巧,需要的朋友可以參考下
    2016-02-02
  • PHP調(diào)用FFMpeg實(shí)現(xiàn)音視頻操作的示例詳解

    PHP調(diào)用FFMpeg實(shí)現(xiàn)音視頻操作的示例詳解

    這篇文章主要為大家詳細(xì)介紹了PHP如何調(diào)用FFMpeg實(shí)現(xiàn)簡(jiǎn)單的音視頻操作,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價(jià)值,感興趣的小伙伴可以了解下
    2023-10-10
  • php表單提交實(shí)例講解

    php表單提交實(shí)例講解

    這篇文章主要介紹了php表單提交實(shí)例,一個(gè)超簡(jiǎn)單的適用于初學(xué)者者的php提交實(shí)例,感興趣的小伙伴們可以參考一下
    2015-11-11
  • php使用curl_init()和curl_multi_init()多線程的速度比較詳解

    php使用curl_init()和curl_multi_init()多線程的速度比較詳解

    這篇文章主要介紹了php使用curl_init()和curl_multi_init()多線程的速度比較,結(jié)合實(shí)例形式詳細(xì)分析了curl_init()和curl_multi_init()的具體使用方法及相關(guān)效率比較,需要的朋友可以參考下
    2018-08-08
  • PHP中使用sleep造成mysql讀取失敗的案例和解決方法

    PHP中使用sleep造成mysql讀取失敗的案例和解決方法

    這篇文章主要介紹了PHP中使用sleep造成mysql讀取失敗的案例和解決方法,如果遇到這個(gè)問題,可能會(huì)耗費(fèi)你N久的時(shí)間,希望你能快速的搜索到這篇文章吧,需要的朋友可以參考下
    2014-08-08
  • PHP中怎樣防止SQL注入分析

    PHP中怎樣防止SQL注入分析

    這篇文章主要介紹了PHP中怎樣防止SQL注入分析,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2014-10-10
  • 深入掌握include_once與require_once的區(qū)別

    深入掌握include_once與require_once的區(qū)別

    要深入掌握include(_once)與require(_once),需要掌握以下幾點(diǎn)內(nèi)容,不過有人建議不建議使用
    2013-06-06
  • PHP中include/require/include_once/require_once使用心得

    PHP中include/require/include_once/require_once使用心得

    include() 、require()語(yǔ)句包含并運(yùn)行指定文件。這兩結(jié)構(gòu)在包含文件上完全一樣,唯一的區(qū)別是對(duì)于錯(cuò)誤的處理。require()語(yǔ)句在遇到包含文件不存在,或是出錯(cuò)的時(shí)候,就停止即行,并報(bào)錯(cuò)。include()則繼續(xù)即行。
    2016-08-08

最新評(píng)論