|
-
- <?php
- if(isset($_POST['send'])){
- header ("Content-type: image/jpeg");
- //取得上傳圖片
- $src=imagecreatefromjpeg($_FILES['p_pic']['tmp_name']);
- //取得來源圖片長寬
- $src_w=imagesx($src);
- $src_h=imagesy($src);
- //假設長寬不超過155
- if($src_w > $src_h){
- $thumb_w = 155;
- $thumb_h = intval($src_h/$src_w*155);
- }else{
- $thumb_h = 155;
- $thumb_w = intval($src_w/$src_h*155);
- }
- // 建立縮圖
- $thumb=imagecreatetruecolor($thumb_w,$thumb_h);
- //開始縮圖
- imagecopyresampled($thumb,$src,0,0,0,0,$thumb_w,$thumb_h,$src_w,$src_h);
- //上傳處理後之圖片
- imagejpeg($thumb,"uploads/".$_FILES['p_pic']['name']);
- //上傳原始圖片
- copy($_FILES['p_pic']['tmp_name'],"test/".$_FILES['p_pic']['name']);
- }
- ?>
- <form method="post" action="uploads.php?check=add" enctype="multipart/form-data">
- <table width="400">
- <tr>
- <td bgcolor="#3892C7" class="tdwh">產品圖片</td>
- </tr>
- <tr>
- <td class="td"><input type="file" name="p_pic" size="30" tabindex="1" />
- </td>
- </tr>
- <tr><td><input type="submit" value="送出" name="send"></td></tr>
- </table>
- </form>
複製代碼 |
|