在文本输入表单中键入代码,如何?

时间:2009-08-24 16:09:09

标签: php forms upload scripting input

我有这个图片上传脚本。

 <?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>"; 
          }
        }

我需要脚本以

的形式写出文件的名称
<form> 
 <input name="animeinput" id="animeinput" size="20" class="textbox"> 
</form>

所以基本上我需要上传脚本在上传图片时将$ imagepath(用于存储图像的文件名)写入表单。

我该怎么做?

2 个答案:

答案 0 :(得分:1)

如果您想要添加到您之前提到的显示图像的脚本中,那么这就是您的意思吗?

...
echo "Large image: <img src='temporary_images/".$imagepath."'><br>"; 
echo "<form>";
echo '<input type="text" value="' . $imagePath . '" name="animeinput" id="animeinput" size="20" class="textbox">'; 
echo "</form>";
...

答案 1 :(得分:0)

我不完全确定你的意思,但这应该有效:

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