开发者

How to get the path of a file before its uploaded?

开发者 https://www.devze.com 2022-12-23 07:13 出处:网络
I have an upload box... <form action=\"upload_file.php\" method=\"post\" enctype=\"multipart/form-开发者_Go百科data\"><BR>

I have an upload box...

<form action="upload_file.php" method="post" enctype="multipart/form-开发者_Go百科data"><BR>
    <label for="file">Filename:</label><BR>
    <input type="file" name="file" id="file" /><BR> 
    <input type="submit" name="submit" value="Submit" />
</form>

Now when I click browse and get the Image I want to upload and click it, it shows the path of the file into the text box that comes with. Now I want to get that path and insert it into a <img> tag so It will show to get a preview before I upload.


Recent browsers won't let you get at that type of info. file inputs are more restrictive for security.


Try this:

<script>
function lalala(str){
    alert(str);
}
</script>

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">

<input type="file" name="file" id="file" onchange="lalala(this.value);" />
</form>

It worked for me in IE8 it gives me the complete path but in firefox and chrome is just prints the file name :(


Sites like Facebook, etc, use signed Java applets for this sort of thing (to enable local file reading), and integrate the image upload into that. Technically, you'd be able to pass data between Java and Javascript to prime it for upload, but the whole thing'd be non-trivial :) Check out http://jumploader.com/ for something which might be of use.

How to get the path of a file before its uploaded?


(source: jumploader.com)

0

精彩评论

暂无评论...
验证码 换一张
取 消