4

I own a local PHP point of Sale, using wampp as my web-server (Win7). What I'm looking for is to find a way to open the Flash Drive E as we normally do by visiting My Computer - > USB Flash E: ... but using JavaScript.

I have found this code, which works perfectly as needed... But this only works on IE, I'm using Google Chrome as my POS browser but what Chrome does... Opens up a blank window!

Here is the code:

<script>
function CallMe()
{
 window.open("file://PCNAME/E$");
}
</script>
<html>
<input  type="button" onClick="CallMe()" value="Open USB" />
</html>

Is there an alternative way to open USB Drive E? Maybe by using PHP?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Alihamra
  • 454
  • 2
  • 10
  • 28
  • 2
    You're only trying to open the window, right? You aren't trying to interact with drive contents? As @madhairsilence indicates, the latter is a *huge* security issue. Er. Indicated. In a now-deleted comment. Just take it from me instead. Huge security risk, the latter. – Charles Jan 02 '13 at 09:36
  • @Charles Yes, Just to open window. – Alihamra Jan 02 '13 at 09:38
  • -1 This is unclear. Are you trying to open the *local drive*'s contents in the browser or some *other computer on the network*'s contents in the browser (Javascript)? Or are you trying to open the server's folder and show it (PHP)? Or are you trying to upload a user's hard drive contents to a server? Side note: "open Local Drive C ... by using PHP" is a little scary to me. – lc. Jan 02 '13 at 09:38
  • @Charles okay but It works on IE ! Ok forget Drive C:, What if i want to open Flash drive? as E: ?? – Alihamra Jan 02 '13 at 09:39
  • No Guys, All Maybe its my fault to add Drive C...I'll edit code above, I want to check Drive E ( USB Flash ) to check if the files transferred or not...Thats all ! – Alihamra Jan 02 '13 at 09:41
  • You can create an href tag and specify file:\\\\[machinetargename]\\c$, but please not this only works in IE. This will open a windows explorer window, not a browser window. Furthermore, this only works on IE, not edge, chrome or firefox for security reasons. – Rudy Hinojosa Feb 18 '20 at 16:23

2 Answers2

8

You could allow the user to navigate their filesystem from the browser using:

<input type="file" />​

You can't specify a default location nor can the browser open it automatically, however.

Brian Ustas
  • 62,713
  • 3
  • 28
  • 21
  • 2
    This opens a file picker, not a navigation tool. They are *not* the same thing, and act *very* differently. – Charles Jan 02 '13 at 09:39
  • 1
    @Alihamra You can't. The user must make all the moves for security reasons. – Brian Ustas Jan 02 '13 at 09:49
  • 2
    Without being able to specify at least the default location this cannot be considered a valid solution. – Brain Aug 10 '18 at 11:58
  • Certainly a "not possible" is a valid solution, especially when it is enforced by browser vendor security implementations. –  Jan 23 '20 at 18:48
4
window.open("file:///" + yourLocalOrNetworkPath);
Hirusha Fernando
  • 1,156
  • 10
  • 29
ZooZ
  • 933
  • 1
  • 17
  • 25