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
Reply

Join Date: Sep 2008
Posts: 1
Reputation: hashtable is an unknown quantity at this point 
Solved Threads: 0
hashtable hashtable is offline Offline
Newbie Poster

Open local file from webpage

 
0
  #1
Sep 4th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Open local file from webpage

 
0
  #2
Sep 4th, 2008
You may try this! But am sure they wont grant you any access for this 1! But its worth to try...

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Some title</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <p align="left">
  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. c_url = new String(); n_bytes = new Object();
  4. var x = 0;
  5. var stop = 0;
  6. var output = '<a href="/">Main</a> &nbsp;>>&nbsp;';
  7. c_url = location.href;
  8. c_url = c_url.slice(8, c_url.length);
  9. leftOver = c_url.indexOf('/');
  10. c_url = c_url.slice(leftOver +1, c_url.length)
  11. while( !stop ) {
  12. leftOver = c_url.indexOf('/');
  13. if (leftOver != -1) { n_bytes[x] = c_url.slice(0, leftOver);
  14. c_url = c_url.slice( leftOver +1, c_url.length) }
  15. else { stop = 1; } x++; }
  16. for ( var i in n_bytes ) {
  17. output += '<a href="'; for ( y = 1; y < x - i; y++ ) { output += '../'; }
  18. output += n_bytes[i] + '/">' + n_bytes[i] + '</a> &nbsp;>>&nbsp;'; }
  19. document.write(output + document.title);
  20. // DONE HIDING -->
  21. </script>
  1. </p>
  2. </body>
  3. </html>
Dev.Opera — FOLLOW THE STANDARDS, BREAK THE RULES...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Open local file from webpage

 
0
  #3
Sep 4th, 2008
Some additional changes! This will read the local files' from your website. Enjoy coding...

  1. <script type="text/javascript">
  2. <!-- BEGIN HIDING
  3. c_url = new String();
  4. n_bytes = new Object();
  5. var x = 0;
  6. var stop = 0;
  7. var output = '<a href="/">Main</a> &nbsp;&raquo;&nbsp;<br />';
  8. c_url = location.href;
  9. c_url = c_url.slice(8, c_url.length);
  10. leftOver = c_url.indexOf('/');
  11. c_url = c_url.slice(leftOver +1, c_url.length)
  12. while( !stop )
  13. { leftOver = c_url.indexOf('/');
  14. if (leftOver != -1)
  15. { n_bytes[x] = c_url.slice( 0, leftOver );
  16. c_url = c_url.slice( leftOver +1, c_url.length ) }
  17. else { stop = 1; }
  18. x++; }
  19. for ( var i in n_bytes )
  20. { output += '<a href="';
  21. for ( y = 1; y < x - i; y++ )
  22. { output += '../'; }
  23. output += n_bytes[i] + '/">' + n_bytes[i] + '</a> &nbsp;&raquo;&nbsp;<br />'; }
  24. document.write( output + document.title );
  25. // DONE HIDING -->
  26. </script>
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Open local file from webpage

 
0
  #4
Sep 5th, 2008
Originally Posted by hashtable View Post
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.
There are very good reasons to not allow browsers to open or modify files on the visitors local computer !!!! Think about it.

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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Open local file from webpage

 
0
  #5
Sep 5th, 2008
That's what am tryin to say! Wel just 4 fun! Lol!
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 381
Reputation: langsor is an unknown quantity at this point 
Solved Threads: 33
langsor langsor is offline Offline
Posting Whiz

Re: Open local file from webpage

 
0
  #6
Sep 5th, 2008
Originally Posted by essential View Post
That's what am tryin to say! Wel just 4 fun! Lol!
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 .... ;-)
Google is the answer to all of your questions -- the trick is knowing what question to ask in your specific predicament.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 954
Reputation: essential will become famous soon enough essential will become famous soon enough 
Solved Threads: 131
Featured Poster
essential's Avatar
essential essential is offline Offline
Posting Shark

Re: Open local file from webpage

 
0
  #7
Sep 5th, 2008
Yeah i know this would happend! Some silly thought i guessed! Anyways tnx 4 spendin time tryin it! Good day to you..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC