It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming JavaScript Forum

upload image preview

upload image preview

Postby aneuryzma on Thu May 07, 2009 11:53 am

Does anybody know if does exist a widget in dojo to have the preview of an uploaded image ?

It the moment i submit and store the image on the server but I would like to display an image preview before to submit the form.
aneuryzma
 
Posts: 41
Joined: Mon Jan 19, 2009 9:10 am

Re: upload image preview

Postby aneuryzma on Thu May 07, 2009 1:49 pm

Hi, I've tried this small script:

Code: Select all
<!-- image preview -->
<script language="javascript">

   var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;

   function previewImage(pathField, previewName) {
   
        console.log(pathField.value);
       
       var path = pathField.value;
       if (path.search(imgRe) != -1) {   
           document[previewName].src = 'file://'+path;
           console.log( 'file://'+path);
       
       } else {   
           alert("JPG, PNG, and GIFs only!");
           
       }   
   }
   
</script>


but the var path contains only "picture1.png" instead of the complete path "User/Desktop/Picture1.png".
aneuryzma
 
Posts: 41
Joined: Mon Jan 19, 2009 9:10 am

Re: upload image preview

Postby aneuryzma on Thu May 07, 2009 1:51 pm

This is the html code


<form name="imageTest" action="upload_file.php" method="post" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" />
<br />
<input type="button" value="Preview!" onClick="previewImage(document.imageTest.file,'replaceMe')"/><br>
<img src="images/clear.gif" name="replaceMe"/>

<input type="hidden" name="MAX_FILE_SIZE" value="131072"/>
<input type="hidden" name="_stage" value="1" />
<input type="submit" name="submit" value="Upload" />
</form>
aneuryzma
 
Posts: 41
Joined: Mon Jan 19, 2009 9:10 am


Who is online

Users browsing this forum: No registered users and 8 guests