php 縮圖

來源:互聯網
上載者:User

標籤:大小   代碼   esx   img   定義   名稱   檔案名稱   部分   doctype   

 

 

<!DOCTYPE html>
<!-- HTML5表單 -->
<form method="post" action="" enctype="multipart/form-data">
<h2>檔案上傳</h2>
<input type="file" name="picture"><br/>
<input type="submit" name="submit" value="提交">
</form>
<!--PHP代碼部分-->
<?php
if(isset($_POST[‘submit‘]))
{
$filename=$_FILES[‘picture‘][‘name‘];//擷取上傳檔案的名稱
$type=$_FILES[‘picture‘][‘type‘];//擷取上傳檔案的類型
$upfile="../good/image/EX5_9.jpg";//上傳後檔案所在的路徑和檔案名稱
$small_upfile="../good/image/EX5_9_small.jpg";//上傳後縮圖所在的路徑和檔案名稱
if(!$filename)//判斷檔案是否存在
{
echo "<script>alert(‘檔案不存在!‘) </script>";
}
//else if($type!=‘image/pjpeg‘)//判斷檔案是否為JPEG格式
//{
//echo "<script>alert(‘檔案格式不正確!‘) </script>";
//}
//else
{
//複製上傳檔案並將檔案儲存為$upfile
move_uploaded_file($_FILES[‘picture‘][‘tmp_name‘],$upfile);
$dst_w=150;//設定縮圖的寬
$dst_h=150;//設定縮圖的高
$src_image=imagecreatefromjpeg($upfile);//讀取上傳後的檔案並建立映像
$src_w=imagesx($src_image);//獲得映像的寬
$src_h=imagesy($src_image);//獲得映像的高
$dst_image=imagecreatetruecolor($dst_w,$dst_h);//建立新映像
//將映像$src_image重新定義大小並寫入新的映像$dst_image中
imagecopyresized($dst_image,$src_image,0,0,0,0,$dst_w,$dst_h,$src_w,$src_h);
imagejpeg($dst_image,$small_upfile);//將新映像儲存為$small_upfile
echo "檔案上傳成功,縮圖如下:<br/>";
echo "<img src=$small_upfile>";//顯示映像
imagedestroy($src_image);
imagedestroy($dst_image);
}
}
?>

php 縮圖

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.