0

i have a simple browse which accepts only images. But after onclick button i can not get the full path in javascript so that i can send them to server by jquery post. i am only getting the filename.

javascript

<script type="text/javascript">
    function post_ad() {

        var img = document.getElementById('img1'),
        tempimg= img.value;

        alert(tempimg);

        jQuery.ajax({
            type: 'POST',
            url: 'process.php',
            data: {
                tempimg: tempimg
             },
             success: function (html) {

             }
         });
    }

</script>

HTML

<input id="img1" name="img1" accept="image/*" type='file'>

<input type="button" onclick="post_ad()" value="click">
Morteza QorbanAlizade
  • 1,520
  • 2
  • 19
  • 35
  • Does it work if you remove the Javascript part completely? – Jonas Grumann Dec 16 '16 at 09:33
  • i dont understand, which javascript part ? – askandanswer Dec 16 '16 at 09:34
  • I mean, if you remove the `onclick="post_ad()"` – Jonas Grumann Dec 16 '16 at 09:35
  • You cannot get full path according to this http://stackoverflow.com/questions/3489133/full-path-from-file-input-using-jquery – Rajashekhar Dec 16 '16 at 09:37
  • You can not get full path but getting name you can generate it accordingly at server side as you know in which folder that image remains – Nikunj Soni Dec 16 '16 at 09:38
  • You can not get a real path from file input. And even if it was possible you would post the path, not the file, so it wouldn't make sense. If you want to post the image using ajax, then it's been answered before, f.e. http://stackoverflow.com/questions/19447435/ajax-upload-image – pawel Dec 16 '16 at 09:38
  • thank You. i will hardcode the full path on server side. – askandanswer Dec 16 '16 at 09:40
  • Your example should give you the URL .. it would say for example `C:/fakepath/filename.png` ? This is a **browser security implementation**. Browser won't allow access to your system disk structure. – Nikhil Nanjappa Dec 16 '16 at 09:52

1 Answers1

0

For security reasons its forbidden. Here its a more complete answer: How to get full path of selected file on change of <input type=‘file’> using javascript, jquery-ajax?

Community
  • 1
  • 1
Lombard
  • 12
  • 3