existance of a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Cherrish Vaidiyan

    existance of a file

    hello scholars,

    i am just learning PHP. i have a small requirement in urgency.i want
    to create a functionality of archiving in which a user can upload any
    file through a browser to a location. but in that functionality. I
    want to solve a small error in my program.The case is explained
    below....

    If i type the path,currently my program dont check for existance of
    the file.ie; even if the file exist or not, the results appears as
    "File uploaded successfully".
    I need to know if there is any function in PHP to verify if the file
    existed or not.Can any one help me to solve this small problem.

    pls do help me...
    Cherrish Vaidiyan
  • Cliff Roman

    #2
    Re: existance of a file

    if (file_exists("< name/path of file>")) {
    <action>
    }


    "Cherrish Vaidiyan" <unbreakablemat rix@yahoo.com> wrote in message
    news:f037d974.0 402241419.45e29 ca3@posting.goo gle.com...[color=blue]
    > hello scholars,
    >
    > i am just learning PHP. i have a small requirement in urgency.i want
    > to create a functionality of archiving in which a user can upload any
    > file through a browser to a location. but in that functionality. I
    > want to solve a small error in my program.The case is explained
    > below....
    >
    > If i type the path,currently my program dont check for existance of
    > the file.ie; even if the file exist or not, the results appears as
    > "File uploaded successfully".
    > I need to know if there is any function in PHP to verify if the file
    > existed or not.Can any one help me to solve this small problem.
    >
    > pls do help me...
    > Cherrish Vaidiyan[/color]


    Comment

    • John Dunlop

      #3
      Re: existance of a file

      Cherrish Vaidiyan wrote:
      [color=blue]
      > i have a small requirement in urgency.[/color]

      Then, with respect, usenet isn't the place.
      [color=blue]
      > i want to create a functionality of archiving in which a user can upload any
      > file through a browser to a location. but in that functionality. I
      > want to solve a small error in my program.The case is explained
      > below....
      >
      > If i type the path,currently my program dont check for existance of
      > the file.ie; even if the file exist or not, the results appears as
      > "File uploaded successfully".
      > I need to know if there is any function in PHP to verify if the file
      > existed or not.[/color]

      The file_exists function has already been suggested:



      But the Manual entry for "Handling file uploads" says, "If no file is
      selected for upload in your form, PHP will return
      $_FILES['userfile']['size'] as 0, and $_FILES['userfile']['tmp_name']
      as none.".



      Moreover, move_uploaded_f ile will return false if its first parameter
      is not a "valid upload file".



      --
      Jock

      Comment

      • John Dunlop

        #4
        Re: existance of a file

        John Dunlop wrote:
        [color=blue]
        > The file_exists function has already been suggested:[/color]

        Well, I forgot that even if the file doesn't exist on your system, by
        typing a filename in, a file is created and store in upload_tmp_dir.
        Say I type in "C:\My Documents\file. txt" (possibly including the
        quotes; presumably users are familiar enough with their browsers to
        know how to handle them) and it doesn't exist, file information is
        still stored in $_FILES, since $_FILES just contains POST data.
        That's only logical.

        The is_uploaded_fil e function therefore returns true; the
        move_uploaded_f ile function moves the file; the original name,
        temporary name, type and size are set; and no errors are given.
        That's all to be expected.

        The size is obviously 0. Maybe you could check that. Otherwise, I
        don't believe there is any other tell-tale signs.

        Ref.: http://www.ietf.org/rfc/rfc1867.txt

        --
        Jock

        Comment

        Working...