Well, I'm not going to steal the url. I want to show a preview of the file in which they are located (for example, if they select an image, I can make it base32 and preview it)
You cannot access or use the local path of the user's file system. This means that you cannot use the real file path on your computer for preview.
If you need a URL / path to access the file to do something like show a preview image, you can create a temporary URL that allows you to do such things. Javascript method for this:
window.URL.createObjectURL(myObject)
( Documentation )
Here is an example of image preview using HTML, Javascript and jQuery ...
<div id="formContainer"> <form action="http://example.com" method="POST"> <input id="imageUploadInput" name="imageUploadInput" type="file" accept="image/*" /> <button id="submitButton" type="submit">Submit</button> </form> </div> <div id="imagePreviewContainer"> </div> <script type="text/javascript"> $("#imageUploadInput").change(function () { var image = this.files[0]; $("#imagePreviewContainer").innerHTML = ''; var imgCaption = document.createElement("p"); imgCaption.innerHTML = image.name; var imgElement = document.createElement("img"); imgElement.src = window.URL.createObjectURL(image); imgElement.onload = function () { window.URL.revokeObjectURL(this.src); }; $("#imagePreviewContainer").innerHTML = ''; </script>
Try it yourself: http://jsfiddle.net/u6Fq7/
source share