Path Function?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ralph Freshour

    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...

  • MeerKat

    #2
    Re: Path Function?

    Ralph Freshour wrote:
    [color=blue]
    > 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...[/color]

    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.
    [color=blue]
    > Thanks...
    >[/color]

    --
    MeerKat

    Comment

    Working...