辦公室、工廠專業搬遷
規劃完整搬遷流程動線,不加價,收費合理!
室內設計師提供壁癌防治、防水抓漏,全程使用A級防水材
改建工程,免付費諮詢

首頁  •  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: &lt;img src='images/".$save."'&gt;&lt;br&gt;";
    }
    }

    ?>



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

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