| | |
Open local file from webpage
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 1
Reputation:
Solved Threads: 0
Hi all,
firstly I'm new here and my English is not perfect but I think it is not important
I have web page where user can upload file. He can select which file to upload with standard HTML input of type file.
I want to add this feature:
when user select some file (e.g. picture, pdf etc.) in file select dialog, I want to add link to selected local file. When user click on it browser(maybe associated application) should open local file so user can review what he selected.
I was experimenting with urls with "file" protocol but it works only with html file located on local computer not for one on web server. I found that this is because of security restriction in browsers.
Can anybody help me please how to open local files or have anybody found idea how to add similar solution?
Thank you for help
firstly I'm new here and my English is not perfect but I think it is not important
I have web page where user can upload file. He can select which file to upload with standard HTML input of type file.
I want to add this feature:
when user select some file (e.g. picture, pdf etc.) in file select dialog, I want to add link to selected local file. When user click on it browser(maybe associated application) should open local file so user can review what he selected.
I was experimenting with urls with "file" protocol but it works only with html file located on local computer not for one on web server. I found that this is because of security restriction in browsers.
Can anybody help me please how to open local files or have anybody found idea how to add similar solution?
Thank you for help
You may try this! But am sure they wont grant you any access for this 1! But its worth to try...
html Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN"> <html> <head> <title>Some title</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p align="left">
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- BEGIN HIDING c_url = new String(); n_bytes = new Object(); var x = 0; var stop = 0; var output = '<a href="/">Main</a> >> '; c_url = location.href; c_url = c_url.slice(8, c_url.length); leftOver = c_url.indexOf('/'); c_url = c_url.slice(leftOver +1, c_url.length) while( !stop ) { leftOver = c_url.indexOf('/'); if (leftOver != -1) { n_bytes[x] = c_url.slice(0, leftOver); c_url = c_url.slice( leftOver +1, c_url.length) } else { stop = 1; } x++; } for ( var i in n_bytes ) { output += '<a href="'; for ( y = 1; y < x - i; y++ ) { output += '../'; } output += n_bytes[i] + '/">' + n_bytes[i] + '</a> >> '; } document.write(output + document.title); // DONE HIDING --> </script>
html Syntax (Toggle Plain Text)
</p> </body> </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Some additional changes! This will read the local files' from your website. Enjoy coding...
javascript Syntax (Toggle Plain Text)
<script type="text/javascript"> <!-- BEGIN HIDING c_url = new String(); n_bytes = new Object(); var x = 0; var stop = 0; var output = '<a href="/">Main</a> » <br />'; c_url = location.href; c_url = c_url.slice(8, c_url.length); leftOver = c_url.indexOf('/'); c_url = c_url.slice(leftOver +1, c_url.length) while( !stop ) { leftOver = c_url.indexOf('/'); if (leftOver != -1) { n_bytes[x] = c_url.slice( 0, leftOver ); c_url = c_url.slice( leftOver +1, c_url.length ) } else { stop = 1; } x++; } for ( var i in n_bytes ) { output += '<a href="'; for ( y = 1; y < x - i; y++ ) { output += '../'; } output += n_bytes[i] + '/">' + n_bytes[i] + '</a> » <br />'; } document.write( output + document.title ); // DONE HIDING --> </script>
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
•
•
•
•
when user select some file (e.g. picture, pdf etc.) in file select dialog, I want to add link to selected local file. When user click on it browser(maybe associated application) should open local file so user can review what he selected.
The best I can suggest is loading the file from the visitor's local machine to the server, then making a link to that file on the server so the visitor can open it using the browser's plugin for that file-type. If the browser doesn't understand or can't handle the mime-type of a specific file it will try to let the visitor download the file, which seems silly seeing as they just uploaded it. But as for opening that file on the visitor's local machine in a program you choose, or even the default program for that file-type, that is a huge security risk and hopefully no one figures out a way to do it.
On the other hand. If you could get the user to download a program that talks to your web server (it could even be written in PHP, if you include the binaries or wrap it as an executable), then you could take over the visitors computer, steal their private data, and erase everything -- mwahahaha!
Peace
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
I had to run your script to see exactly what it was doing -- the c_url variable confused me for some reason?
Pretty cool idea actually ... but still the only way to take over a visitor's computer (that I know how to do) is to convince them to download a file to their local computer .... ;-)
Pretty cool idea actually ... but still the only way to take over a visitor's computer (that I know how to do) is to convince them to download a file to their local computer .... ;-)
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
![]() |
Similar Threads
- Windows Explorer Problem/Virus (Viruses, Spyware and other Nasties)
- Cant open certain links in a web page... (Viruses, Spyware and other Nasties)
- DSL is connected. webpages wont download? (Networking Hardware Configuration)
- High CPU usage with no programs running (Windows NT / 2000 / XP)
- HiJackThis log - Could someone have a look? Windows explorer won't open (Viruses, Spyware and other Nasties)
- storing details as html doc using php (PHP)
- generating txt using php (PHP)
- Trojan-Spy.HTML.Smitfraud.c (Viruses, Spyware and other Nasties)
- HighJackThis File Log, Please Help! (Viruses, Spyware and other Nasties)
- Hijack Help (Viruses, Spyware and other Nasties)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Problem with Radio Button / AJAX
- Next Thread: The code looks right but does not work.
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxjspservlets array browser bug calendar captchaformproblem cart checkbox child class close codes createrange() cursor date debugger decimal dependent disablefirebug dom dropdown editor element embed engine enter events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe images internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps masterpage math media menu object onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post programming progressbar prototype redirect regex runtime safari scale scriptlets scroll search security shopping size software sql text textarea toggle unicode web windowsxp wysiwyg \n





