各式房屋拆除,隔間磚牆打除,垃圾清運
免費估價,收費公道
輕鬆估價網優質設計團隊服務,打造幸福居家空間
免費諮詢丈量,裝潢設計首選
J2H流行雜誌J2h論壇程式設計討論   
交友配對個人設定加入會員會員說明重新登入


[php] 上傳照片and 縮圖

房東:jack
發表時間:2017-11-24
[檢舉]


<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="new_image" id="new_image" size="30" type="file" class="fileUpload" />
<button name="submit" type="submit" class="submitButton">Upload Image</button>
</form>
<?php
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: <img src='images/".$imagepath."'><br>";
//echo "Thumbnail: <img src='images/sml_".$imagepath."'>";

}
}
?>




  • J2H贊助網站            在此刊登廣告

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

  • 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 頁】 

    回應主題
    ※注意 
    1. 抱歉,您的網頁未支援Cookie,此網頁將無法正常執行請檢查您電腦瀏覽器關於cookie的設定。設定方法說明
    2. 必須由首頁登入 J2H 流行雜誌