2009-08-24 4 views
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> 
+0

양식과 코드는 무엇입니까? – Zed

답변

2

하는 경우입니다 마크 업에 사용할 수있는 var가 있습니다.

<form> 
    <input name="animeinput" id="animeinput" size="20" class="textbox" value="<?php echo htmlspecialchars($imagePath); ?>" /> 
</form> 
+0

내 "스크립트"는 업로드 스크립트입니다. 그리고 페이지를로드 할 때 업로드 한 이미지가 없으므로 $ imagepath를 쓸 수 없습니다 .. 이미지에 $ imagePath를 입력하고 싶습니다. 업로드되어 사진의 이름이 표시됩니다. 어떻게해야합니까? –

+0

@Per, 양식이 위의 업로드 코드와 동일한 스크립트 파일에있는 경우 마크 업을 만들 때 $ imagePath를 사용할 수 있습니다. 마크 업에 추가해야하는지 확인하기 위해 null을 테스트 할 수 있습니다. –

0

참고 이 작업을 수행 할 때 종종 캐싱 및 타이밍 문제가 발생할 수 있습니다 (양식을 제출 한 후에 실제로 이미지를 보는 데 문제가있는 경우 아래 참조).이 이미지는 결과 페이지가로드되는 시간. jquery/ajax로 이미지를 업데이트하여이 문제를 해결했습니다.

일단 양식이 게시되고 이미지가 업로드되면 숨겨진 태그 #large_image에 이미지에 대한 참조를 저장합니다. 당신은 이미지의 경로와 숨겨진 태그를 에코 것이다 됨 src 그런 이미지 대신 메아리의 후 귀하의 경우에는이 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" />'); 
} 

}); 

를 사용합니다.

희망이 있습니다.

+0

나는 내가 의도 한 것을 가지고 있다고 생각하지 않습니다. http://www.anitard.org/siggen/siggen_stripes/ 이미지를 업로드하면 그림이 나타납니다. 는하지만 난 형태로

<입력 이름 = "animeinput"ID = "animeinput"크기 = "20"클래스 = "텍스트 상자">
을 파일의 이름을 작성하는 스크립트를 필요 –

관련 문제