37582

Type code in to a text input form, how?

Question:

I want to know the best way of writing out my "$imagepath" in to this input

This is my upload script

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

And this is my form

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

Answer1:

If you've got the var available to the markup:

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

Answer2:

Note that there can often be an issue with caching and timing when doing this (so if you are having problems actually seeing your image after submitting your form then see below), I guess this has something to do with the image not being in place by the time the resulting page is loaded. I got around this issue by updating my image with jquery/ajax.

Once the form is posted and image uploaded I save a reference to the image in a hidden tag #large_image. Then use this 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" />'); } });

In your case then, instead of echoing the image src you would echo a hidden tag with a path to the image.

Hope this helps :)

Recommend

  • Create square 1:1 thumbnail in PHP
  • Center watermark text on image when unknown size of text
  • resizing image function implementation inpage
  • dynamic image resize using php
  • PHP - Fatal Error - is any way to not stop script? [duplicate]
  • Generated image using PHP and GD is being cut off
  • Having issues with GD thumbnail generator
  • php GD image resizing to smaller new image -> blurring problem
  • PHP remove exif data from images
  • Display an image after resizing
  • Upload image from Android to MySQL database
  • Zend captcha Image generates blank
  • PHP: How to output image files?
  • Flip an Image horizontally
  • return dynamic image zf2
  • Python telnet works in command line but not in script
  • Broken Cyrillic file name when uploading to server
  • No orientation in exif data - PHP image upload
  • Geting json response from Google places API in android
  • PHP Keep exif data using imagecopyresampled
  • Upload image without losing quality
  • JMeter JMS Point-to-Point Request Response: “No reply message received”
  • Geting json response from Google places API in android
  • Fatal Exception: android.view.WindowManager$BadTokenException Unable to add window — token is not va
  • Excel macros Help. Creating a new column based of arrays.
  • How to narrow down the current aggregation context to a specific scope within set of documents retur
  • Passing file path to php script
  • Watermark text using imagettftext
  • Error “Connection reset” in JMeter (SOAP XML web-service)
  • select top N dynamically with N from the same select statement
  • data.frame rows to list named elements
  • resize png/jpeg image
  • Click button with javascript
  • How does document.ready work with angular element directives?
  • Using a canvas object in a thread to do simple animations - Java
  • How can I enlarge video fullscreen without the affected interface project in as3?
  • Python urlparse: small issue
  • FileReader+canvas image loading problem
  • Resize panoramic image to fixed size
  • python draw pie shapes with colour filled