File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes Accessing the full path of a file uploaded via an HTML form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Accessing the full path of a file uploaded via an HTML form" Watch "Accessing the full path of a file uploaded via an HTML form" New topic
Author

Accessing the full path of a file uploaded via an HTML form

E.J. Necuima
Greenhorn

Joined: Jan 24, 2009
Posts: 4
Hi,

Can anyone help me with this simple question? I have Googled quite a bit but so far without success.

I have an HTML form which selects a file. I want to pass the full path of this file to another PHP/HTML script. It works fine in IE6 but not in Firefox. Specifically, all that gets passed in FF is the file name and not its path. Can anyone help?

Thanks in anticipation.



Thanks, Necuima1
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
You should not get the file path. You should get the file contents. This is only going to work when both the client and the server runs at the same machine. Imagine that I give you a file path of my local file system, are you able to access it through the network from your machine?

IE has the misbehaviour that it sends the complete path instead of only the filename. Firefox (and all other webbrowsers) is doing it right. Fo fix this IE misbehaviour and get only the filename, just trim everything away before the last slash.

In PHP you can get the file contents by $_FILES. Just google a decent PHP file upload tutorial for a how to.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
It is impossible to get it to work since it is added security measures to protect the user. I still do not understand why people need the full path in a web application.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

I'n interested too, as this question comes up fairly often. Why do you need the original file path from the client?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
E.J. Necuima
Greenhorn

Joined: Jan 24, 2009
Posts: 4
Hi Bear, Eric, Bauke,

Thanks for your thoughts so promptly!

I am actually trying to get the path of the directory within which the file exists. The called script then cycles through all the files in that directory and processes them. Specifically, the script resizes (downsizes) all the jpg images in the directory. And yes, it so happens that I am running both the server and the client on the same PC.

FYI my environment is:
. Dell Core 2 Duo PC
. Windows XP Pro SP3
. PHP version 5.2.6
. IIS version 5.1
. MySQL version 5.0.51b-community-nt
. Dreamweaver MX2004 version 7 as the "text editor"
. Internet Explorer version 6.0.2900
. sendmail.exe
. Adobe AIR runtime version 1.5.0.7220
. Aptana Studio version 1.0.0.0
All running on the Dell PC - i.e., all executions are via 'localhost'

When I was developing this application, I was advised that the above technique was the only way to select a directory (on the client) in HTML/PHP without hard-coding it.

I have recently installed Adobe AIR to see if I can figure out how to do this without needing server functionality on my PC. But I've only just started to use AIR so am very much a babe in the woods with that technology so far. (I'm also only a beginner with JavaScript too). But I do see that you can select a directory (on the client) with JavaScript within AIR but I haven't gone further than that yet. There can be hundreds of jpg images in directory that I am trying to process, so downsizing them one-by-one is impractical.

While I'm at it, does anyone know how to resize images using JS/AIR? The PHP code to do this is quite neat and I found it via Googling on the 'net.

Again, thanks for your thoughts/advice so far.

Cheers from Oz,

E.J.
E.J. Necuima
Greenhorn

Joined: Jan 24, 2009
Posts: 4
One further point, I need to actually downsize the size of the jpg files, not just their appearance on a screen. They later get uploaded to an image server.

Cheers
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

This is not the forum to discuss AIR issues, but keeping in the "normal" HTML/JavaScript realm:
E.J. Necuima wrote:I am actually trying to get the path of the directory within which the file exists. The called script then cycles through all the files in that directory and processes them.

This is unachievable as even if you have the client file path, the server code has no way to access the client file system. Thank goodness. Just imagine the security implications otherwise!

You are limited to the files that the user explicitly uploads to you via a file upload operation.
E.J. Necuima
Greenhorn

Joined: Jan 24, 2009
Posts: 4
Hi Bear, thanks for your advice.

I will pursue the AIR option separately. Do you know of a good AIR forum?

Thanks, E.J.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Hmm, not off the top of my head. You could try the Ranch's Application Framework forum, but I'm not sure that there's been lot of AIR traffic there.
 
Don't get me started about those stupid light bulbs.
 
subject: Accessing the full path of a file uploaded via an HTML form