国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > PHP > 正文

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

2024-05-04 23:33:47
字體:
供稿:網(wǎng)友

這篇文章主要介紹了php實(shí)現(xiàn)從上傳文件創(chuàng)建縮略圖的方法,涉及php操作上傳文件及圖片操作的技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

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

 

 
  1. <?php 
  2. if ($_REQUEST['action']=="add"){ 
  3. $userfile = $HTTP_POST_FILES['photo']['tmp_name']; 
  4. $userfile_name = $HTTP_POST_FILES['photo']['name']; 
  5. $userfile_size = $HTTP_POST_FILES['photo']['size']; 
  6. $userfile_type = $HTTP_POST_FILES['photo']['type']; 
  7. /////////////////////////  
  8. //GET-DECLARE DIMENSIONS // 
  9. $dimension = getimagesize($userfile); 
  10. $large_width = $dimension[0]; // GET PHOTO WIDTH 
  11. $large_height = $dimension[1]; //GET PHOTO HEIGHT 
  12. $small_width = 120; // DECLARE THUMB WIDTH 
  13. $small_height = 90; // DECLARE THUMB HEIGHT 
  14. ///////////////////////// 
  15. //CHECK SIZE // 
  16. if ($userfile_size>102400){ 
  17. $error=1; 
  18. $msg = "The photo is over 100kb. Please try again."
  19. //////////////////////////////// 
  20. // CHECK TYPE (IE AND OTHERS) // 
  21. if ($userfile_type="image/pjpeg"){ 
  22. if ($userfile_type!="image/jpeg"){ 
  23. $error=1; 
  24. $msg = "The photo must be JPG"
  25. ////////////////////////////// 
  26. //CHECK WIDTH/HEIGHT // 
  27. if ($large_width!=600 or$large_height!=400){ 
  28. $error=1; 
  29. $msg = "The photo must be 600x400 pixels"
  30. /////////////////////////////////////////// 
  31. //CREATE THUMB / UPLOAD THUMB AND PHOTO /// 
  32. if ($error<>1){ 
  33. $image = $userfile_name//if you want to insert it to the database 
  34. $pic = imagecreatefromjpeg($userfile); 
  35. $small = imagecreatetruecolor($small_width,$small_height); 
  36. imagecopyresampled($small,$pic,0,0,0,0, $small_width$small_height$large_width$large_height); 
  37. if (imagejpeg($small,"path/to/folder/to/upload/thumb".$userfile_name, 100)){  
  38. $large = imagecreatetruecolor($large_width,$large_height); 
  39. imagecopyresampled($large,$pic,0,0,0,0, $large_width$large_height$large_width$large_height); 
  40. if (imagejpeg($large,"path/to/folder/to/upload/photo".$userfile_name, 100)) 
  41. {} 
  42. else {$msg="A problem has occured. Please try again."$error=1;} 
  43. else { 
  44. $msg="A problem has occured. Please try again."$error=1; 
  45. ////////////////////////////////////////////// 
  46. /// If everything went right a photo (600x400) and 
  47. /// a thumb(120x90) were uploaded to the given folders 
  48. ?> 
  49. <html><head><title>create thumb</title></head> 
  50. <body> 
  51. <form name="form1" enctype="multipart/form-data" action="thisfile.php?action=add" method="post"
  52. Select Photo: <input type="file" name="photo"
  53. <input type="submit" name="submit" value="CREATE THUMB AND UPLOAD"
  54. </form> 
  55. </body 
  56. </html> 

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

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 调兵山市| 临海市| 盱眙县| 丰县| 泌阳县| 河北省| 肥西县| 津市市| 天镇县| 玉溪市| 海门市| 九寨沟县| 张家界市| 长沙县| 富川| 长岛县| 德钦县| 娄底市| 古浪县| 东乌珠穆沁旗| 保靖县| 靖远县| 淄博市| 哈尔滨市| 邯郸市| 巴南区| 江阴市| 陇西县| 琼海市| 惠州市| 辛集市| 河津市| 古蔺县| 苗栗市| 临海市| 台湾省| 平定县| 鹤峰县| 金门县| 杭锦后旗| 北辰区|