Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html file upload preview by Javascript

I want to show a PREVIEW kind of thing for an post , so took details by JS

but problem comes when it comes to <input type="file" , it's not giving full path to the file

Ex: if I do

$("#image").val();

it only give "Sunset.jpg" not C:\Documents and Settings\All Users....\Sunset.jpg

any idea how to get that detail value?

like image 224
Posto Avatar asked Dec 18 '22 06:12

Posto


1 Answers

Although, as others have already pointed out, you cannot learn the full path to the file in JavaScript, perhaps a completely different approach to the problem might still work for you.

You could upload the photo automatically as soon as the visitor has picked it (the behavior you see in GMail, among other applications), so it's residing on your server even as the visitor continues interacting with your page. At that point, showing a preview is as simple as serving one yourself from your own (now server-side) copy of the image.

like image 138
VoteyDisciple Avatar answered Dec 28 '22 12:12

VoteyDisciple