SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: $_files

  1. #1
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_files

    How would I extract the filename and extension of the file that was uploaded?

    Would it be any different if there were two files?

  2. #2
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    file extension maybe this way:

    PHP Code:
    $file "db_class.inc.php";
    $ext explode("."$file);
    echo 
    end($ext); // should output php
    echo ext[0]; // should output db_class 
    You need to modify this for files ".htaccess" but generally it should work.

  3. #3
    SitePoint Wizard Chris82's Avatar
    Join Date
    Mar 2002
    Location
    Osnabrück
    Posts
    1,003
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If there are two or more files you would need to use a loop. for or foreach

  4. #4
    SitePoint Guru
    Join Date
    Apr 2001
    Location
    BC, Canada
    Posts
    630
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Problem with that is that I must assume that I know the name of the file. When a file is uploaded through the form via post, I dont know the original name of the file..

  5. #5
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you want the filename from the user's system, right?

    PHP Code:
    // Filename on user's system
    $name $_FILES['form_file']['name'];
    // Extension
    $ext substr(strrchr($_FILES['form_file']['name'], '.'), 1); 
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  6. #6
    SitePoint Evangelist CyberFuture's Avatar
    Join Date
    May 2001
    Location
    San Diego, CA
    Posts
    434
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not just get the mime type? Using Dr. LArry Pepper's code:
    PHP Code:
    // Filename on user's system
    $name $_FILES['form_file']['name'];
    // File Type
    $mime $_FILES['form_file']['type']; 


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •