• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2458
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'n interested too, as this question comes up fairly often. Why do you need the original file path from the client?
 
E.J. Necuima
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic