提供店面、居家、廠房
辦公室建物及裝潢拆除工程,歡迎來電洽詢
裝潢設計外包網專業鐵皮屋搭建工程,免費到府丈量估價
提供保固,歡迎洽詢

首頁  •  j2h 論壇 • 程式設計討論     • 

[php] 上傳照片and 縮圖

房東:jack
發表時間:2017-11-24






if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "images/".$imagename;
move_uploaded_file($source, $target);

$imagepath = $imagename;
$save = "images/" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file

list($width, $height) = getimagesize($file) ;

$modwidth = 500;

$diff = $width / $modwidth;

$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100) ;
/*
$save = "images/sml_" . $imagepath; //This is the new file you saving
$file = "images/" . $imagepath; //This is the original file

list($width, $height) = getimagesize($file) ;

$modwidth = 80;

$diff = $width / $modwidth;

$modheight = $height / $diff;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

imagejpeg($tn, $save, 100) ; */
echo "Large image:
";
//echo "Thumbnail: ";

}
}
?>




  • 贊助網站       

    廣利不動產-新板特區指名度最高、值得您信賴的好房仲
    您的托付,廣利用心為您服務
    廣利不動產-板橋在地生根最實在--新板特區指名度最高、值得您信賴的好房仲
    完整房訊,房屋、店面熱門精選物件,廣利不動產 優質仲介,房屋租賃、買賣資訊透明,交易真安心!

  • 1 樓住戶:老師傅
    發表時間:2017-11-24

    when I looked through your code it seems like you are trying to save the original file in the same place as the resized file. This might be what the problem is.

    Here is what I would suggest.

    Move the uploaded file into a directory called "temp." After you have finished editing it, you can delete it.

    Here is the modified code. Untested.

    if(isset($_POST['submit'])){
    if (isset ($_FILES['new_image'])){
    $imagename = $_FILES['new_image']['name'];
    $source = $_FILES['new_image']['tmp_name'];
    $target = "temp/".$imagename;

    move_uploaded_file($source, $target);

    $imagepath = $imagename;
    $save = "images/" . $imagepath; //This is the new file you saving

    list($width, $height) = getimagesize($target);

    $modwidth = 500;
    $diff = $width / $modwidth;
    $modheight = $height / $diff;

    $tn = imagecreatetruecolor($modwidth, $modheight) ;
    $image = imagecreatefromjpeg($file) ;
    imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;

    imagejpeg($tn, $save, 100) ;
    unlink($target); //Delete our uploaded file

    echo "Large image: <img src='images/".$save."'><br>";
    }
    }

    ?>



     共 1 人回應  選擇頁數 【第1 頁】 

    姓名:
    佈告內容:
    其他選項: