By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,830 Members | 2,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,830 IT Pros & Developers. It's quick & easy.

Path Function?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.