470,862 Members | 1,835 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,862 developers. It's quick & easy.

Path Function?

I'm reading the php manual to find out how to get the path of a file
I'm uploading from my PC - I'm using the $_FILES[FileToUpload][name]
var but that is just the filename - is there a function that I can use
to get it's full path too? or is it by the time php gets it it's on
the server so it's too late to worry about it? do I have to get into
javascript to get the path on the PC side??? I'm trying to check the
filesize before having to upload the file to the server only to find
out it's too big for the limit I'm setting...

Thanks...

Jul 16 '05 #1
1 4095
Ralph Freshour wrote:
I'm reading the php manual to find out how to get the path of a file
I'm uploading from my PC - I'm using the $_FILES[FileToUpload][name]
var but that is just the filename - is there a function that I can use
to get it's full path too? or is it by the time php gets it it's on
the server so it's too late to worry about it? do I have to get into
javascript to get the path on the PC side??? I'm trying to check the
filesize before having to upload the file to the server only to find
out it's too big for the limit I'm setting...
As far as I'm aware, the path to the file on the client machine is not
available in PHP - like you say, there's no point in knowing it (and it
could constitute a security issue, knowing things about the client's
file structure).

However, if you really must have it (but don't mind it not being
available if the client doesn't have Javascript turned on), you could
have a hidden text field in your form which gets populated with the
contents of the file upload field when the form is submitted.

I think the reasons you are wanting to do this are fruitless however.
You say you want to check the size of the file before it is uploaded.
This can't be done. The only way the server can know how big it is is by
uploading it fully. Javascript cannot get access to the filesize on the
client machine for security reasons (it cannot access the client's
filesystem).

That said, you can set MAX_FILE_SIZE, which cause PHP to report straight
away if the size of the file to be uploaded is too big, in which case
the file won't be uploaded at all (the browser doesn't bother). This
isn't the case in all browsers, but I think IE6 plays fair so you'll be
catching the majority of users. You will, of course, still have to code
for those browsers which will still upload the file.

Hope this helps.

MK.
Thanks...


--
MeerKat

Jul 16 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

70 posts views Thread by Michael Hoffman | last post: by
34 posts views Thread by Reinhold Birkenfeld | last post: by
5 posts views Thread by Jean Paul Sartre | last post: by
2 posts views Thread by Rob Cowie | last post: by
4 posts views Thread by tommaso.gastaldi | last post: by
5 posts views Thread by 7stud | last post: by
13 posts views Thread by lawpoop | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.