php實現(xiàn)從上傳文件創(chuàng)建縮略圖的方法
更新時間:2015年04月02日 11:29:44 作者:不吃皮蛋
這篇文章主要介紹了php實現(xiàn)從上傳文件創(chuàng)建縮略圖的方法,涉及php操作上傳文件及圖片操作的技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了php實現(xiàn)從上傳文件創(chuàng)建縮略圖的方法。分享給大家供大家參考。具體實現(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>
希望本文所述對大家的php程序設(shè)計有所幫助。
相關(guān)文章
php+websocket 實現(xiàn)的聊天室功能詳解
這篇文章主要介紹了php+websocket 實現(xiàn)的聊天室功能,結(jié)合實例形式詳細(xì)分析了php+websocket 實現(xiàn)的聊天室功能相關(guān)配置、實現(xiàn)方法與操作注意事項,需要的朋友可以參考下2020-05-05PHP調(diào)用FFMpeg實現(xiàn)音視頻操作的示例詳解
這篇文章主要為大家詳細(xì)介紹了PHP如何調(diào)用FFMpeg實現(xiàn)簡單的音視頻操作,文中的示例代碼講解詳細(xì),具有一定的學(xué)習(xí)價值,感興趣的小伙伴可以了解下2023-10-10php使用curl_init()和curl_multi_init()多線程的速度比較詳解
這篇文章主要介紹了php使用curl_init()和curl_multi_init()多線程的速度比較,結(jié)合實例形式詳細(xì)分析了curl_init()和curl_multi_init()的具體使用方法及相關(guān)效率比較,需要的朋友可以參考下2018-08-08PHP中使用sleep造成mysql讀取失敗的案例和解決方法
這篇文章主要介紹了PHP中使用sleep造成mysql讀取失敗的案例和解決方法,如果遇到這個問題,可能會耗費(fèi)你N久的時間,希望你能快速的搜索到這篇文章吧,需要的朋友可以參考下2014-08-08深入掌握include_once與require_once的區(qū)別
要深入掌握include(_once)與require(_once),需要掌握以下幾點內(nèi)容,不過有人建議不建議使用2013-06-06PHP中include/require/include_once/require_once使用心得
include() 、require()語句包含并運(yùn)行指定文件。這兩結(jié)構(gòu)在包含文件上完全一樣,唯一的區(qū)別是對于錯誤的處理。require()語句在遇到包含文件不存在,或是出錯的時候,就停止即行,并報錯。include()則繼續(xù)即行。2016-08-08