How can display the image preview before saving an image to folder using cakephp?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mohan lal
    New Member
    • Mar 2011
    • 25

    How can display the image preview before saving an image to folder using cakephp?

    Hi..

    I have a form for storing the details of a student In that form there is a field for uploading the student image .How can i display the image preview of a student ?

    If anyone knows please help me . thanks in advance..
  • omerbutt
    Contributor
    • Nov 2006
    • 638

    #2
    one the way i know is javascript
    [code=html]
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Untitl ed Document</title>
    <script type="text/javascript" src="../stage/js/jquery-1.4.2.min.js"></script>
    <script type="text/javascript">
    function imageURL(input) {
    if (input.files && input.files[0]) {
    var reader = new FileReader();
    reader.onload = function(e) {
    $('#preview_img ').attr('src', e.target.result )
    .width('auto')
    .height('auto') ;
    }
    reader.readAsDa taURL(input.fil es[0]);
    }
    }
    </script>
    </head>
    <body>
    <input type="file" class="file" onchange="image URL(this)" />
    <img id="preview_img " style="width:au to; height:auto;" />
    </body>
    </html>
    [/code]

    YOU NEED TO CHANGE THE JQUERY SRC WITH YOUR PATH

    but this will not work for IE as IE shows URL differently from firefox and chrome so you need to work out to check the navigator agent to get the right path
    regards,
    Omer Aslam

    Comment

    • mohan lal
      New Member
      • Mar 2011
      • 25

      #3
      hi.
      thanks for your replay its working fine for me in firefox..thank you...

      Comment

      • omerbutt
        Contributor
        • Nov 2006
        • 638

        #4
        Please choose the best answer whenever the solution works for you , so that its helpful to others who have the same problem .
        Regards,
        Omer Aslma

        Comment

        Working...