0

この入力に「$imagepath」を書き出す最良の方法を知りたい

これは私のアップロードスクリプトです

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

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

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

              $modwidth = 350;                         
              $modheight = 100; 

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

              imagejpeg($tn, $save, 100) ; 

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

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

              $modwidth = 80; 
              $modheight = 100; 

              $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='temporary_images/".$imagepath."'><br>"; 
            echo "$imagepath"
          }
        }

そして、これが私のフォームです

<form>
 <input name="animeinput" id="animeinput" size="20" class="textbox">
</form>
4

2 に答える 2

2

マークアップで使用できる var がある場合:

<form>
   <input name="animeinput" id="animeinput" size="20" class="textbox" value="<?php echo htmlspecialchars($imagePath); ?>" />
</form>
于 2009-08-24T09:13:14.647 に答える
0

これを行うと、キャッシングとタイミングに問題が発生する可能性があることに注意してください(フォームを送信した後に実際に画像を表示するのに問題がある場合は、以下を参照してください)、これは画像が配置されていないことに関係していると思います結果のページがロードされる時間。jquery/ajax でイメージを更新することで、この問題を回避しました。

フォームが投稿され、画像がアップロードされたら、画像への参照を隠しタグ #large_image に保存します。次に、このjqueryを使用します....

$(document).ready(function(){

    //read in hidden reference to image URL
var large_photo = $("#large_image").val();

   //display relevent image (use placeholder if no image uploaded yet)
if (large_photo != "") {
    $("#photo_holder").html('<img src="' + large_photo + '" />');
} else {
    $("#photo_holder").html('<img src="noimagefound.png" />'); 
}

});

あなたの場合、画像 src をエコーする代わりに、画像へのパスを持つ隠しタグをエコーし​​ます。

お役に立てれば :)

于 2009-08-24T09:41:54.667 に答える