Member Avatar for hashtable

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 :)

You may try this! But am sure they wont grant you any access for this 1! But its worth to try...

<!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">
<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> &nbsp;>>&nbsp;'; 
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> &nbsp;>>&nbsp;'; } 
document.write(output + document.title); 
// DONE HIDING --> 
</script>
</p> 
</body> 
</html>

Some additional changes! This will read the local files' from your website. Enjoy coding...

<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> &nbsp;&raquo;&nbsp;<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> &nbsp;&raquo;&nbsp;<br />'; } 
document.write( output + document.title ); 
// DONE HIDING --> 
</script>
Member Avatar for langsor

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

That's what am tryin to say! Wel just 4 fun! Lol!

Member Avatar for langsor

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 .... ;-)

Yeah i know this would happend! Some silly thought i guessed! Anyways tnx 4 spendin time tryin it! Good day to you..

The code snippet is awesome.Its working fine.And my requirement is i want open these file in a text editor.I have developed simple text editor.I need to open the selected file on that text area.How to approach.Expecting the best answers......:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.