Jump to content

Preview A Url Image Link Before Uploading


friedice

Recommended Posts

i want to display the image of a url image

while dynamically loaded on a div under the input type

is there a way to do it?

form method="POST"  action="upload.php">
 <br/><br/>
  <pre>Upload File:  <input type="file" name="images" id="images"/>
  </br>Use Url:	  <input type="text" name="urlimages" id="urlimages" style="width:280px;" value=""/>

  </pre>


  <button type="submit" id="btn">Publish Files!</button>
 </form>
  <div id="response"></div>
   <ul id="image-list"> 
   <pre><p id="imgdesc" >Description:  <textarea   rows="2"  style="width:395px;"></textarea></p></pre>
 </ul>
 <div id="imageHolder"></div>

i got upload file part to work to preview but not this one

 

i think because its on the server side ...

Link to comment
Share on other sites

i tried using the same way as the input-file type method i got workin

which is this function

(function () {
var input = document.getElementById("urlimages"),
 formdata = false;
function showUploadedItem (source) {
   var list = document.getElementById("image-list"),
 li   = document.createElement("li"),
 img  = document.createElement("img");
  p = document.createElement("p");
   img.src = source;
 alert(img.src);
   li.appendChild(img);
 list.appendChild(li);
 li.appendChild(p);
}  
if (window.FormData) {
   formdata = new FormData();
   document.getElementById("btn").style.display = "none";
}

 input.addEventListener("change", function (evt) {
  document.getElementById("response").innerHTML = "checking image . . ."
 document.getElementById("imgdesc").style.display = "block";

 if (formdata) {
  $.ajax({
   url: "upload.php",
   type: "POST",
   data: formdata,
   processData: false,
   contentType: false,
   success: function (res) {
 document.getElementById("response").innerHTML = res;
   }

  });
 }
}, false);
}());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.