PHP
  Home arrow PHP arrow Page 3 - Retrieving Information on Selected Files with a PHP 5 File Uploader
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PHP

Retrieving Information on Selected Files with a PHP 5 File Uploader
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 5
    2008-03-26


    Table of Contents:
  • Retrieving Information on Selected Files with a PHP 5 File Uploader
  • Reintroducing a previous hands-on example
  • Retrieving useful information on the uploaded file
  • Listing the complete source code of the improved file uploading application

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Retrieving Information on Selected Files with a PHP 5 File Uploader - Retrieving useful information on the uploaded file
    ( Page 3 of 4 )

    As you probably know, the $_FILES superglobal array available in PHP allows you to retrieve all the information related to a specific file uploading process, including the MIME type and size, its temporary denomination, etc. Thus, based upon the capabilities of this useful array, I’m going to modify the script that I built in the previous article of this series so it can use the array in question to display detailed information about a particular file upload on the browser.

    That being explained, please take some time to examine the signature of the improved file uploading script, which now looks like this:


    // basic example on uploading a file to the server via HTTP and displaying information on it

    if($_POST['send']){

    // set upload directory (for Windows users)

    $uploadDir='C:uploaded_files';

    // set destination of uploaded file

    $uploadFile=$uploadDir.basename($_FILES['userfile']['name']);

    if(move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadFile)){

    echo 'The target file was successfully uploaded!<br />';

    echo 'Name of uploaded file: '.$_FILES['userfile']['name'].'.<br />';

    echo 'MIME type of uploaded file: '.$_FILES['userfile']['type'].'.<br />';

    echo 'Size of uploaded file: '.$_FILES['userfile']['size'].' bytes.<br />';

    echo 'Temporary name of uploaded file: '.$_FILES['userfile']['tmp_name'].'<br />';

    }

    else{

    echo 'Error uploading target file!';

    }

    }


    As you can see, understanding the logic implemented by the above file uploading script is actually a no-brainer process that can be tackled with minor problems. In this specific case, the script uses a few elements included into the previously mentioned $_FILES PHP array in order to retrieve useful information about a particular file uploading process.

    What’s more, once a targeted file has been successfully uploaded to the web server, the script in question echoes all the data related to this procedure to the browser, including the client name of the pertinent file and other relevant details, such as its MIME type and size in bytes, and its temporary name as well.

    Therefore, based on the recently improved logic of the previous file uploading script, it’s quite easy to retrieve detailed information on a specific file. For instance, say that I just uploaded a sample “test.doc” file to the web server, which would produce the following result:


    The target file was successfully uploaded!

    Name of uploaded file: test.doc.

    MIME type of uploaded file: application/ms-word.

    Size of uploaded file: 19968 bytes.

    Temporary name of uploaded file: C:uploaded_filesphp135.tmp


    That was pretty useful, right? I’m not saying that the $_FILES superglobal array is going to change your life as a PHP developer, but you must admit it works pretty well when it comes to getting meaningful information regarding a specific file uploading process.

    All right, at this point I'll assume that you've already grasped how to use the aforementioned $_FILES PHP array to display all the data related to a particular file upload. So, what’s the next step to take?

    Well, in the last section of this tutorial, I’m going to list the complete source code of this improved file uploading PHP application, including the corresponding upload web form and the modified script that you learned a few lines before so you can copy it and paste it directly into your code editor for testing purposes.

    As I said earlier, this process will be done in the following section, so jump forward and keep reading.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Implementing Factory Methods in PHP 5
    - Merging a File Split for FTP Upload using PHP
    - Getting Data from Yahoo Site Explorer Inboun...
    - Method Chaining: Adding More Selecting Metho...
    - How to Split a File During an FTP Upload Usi...
    - Expanding a Custom CodeIgniter Library with ...
    - Using the Yahoo Site Explorer Inbound Links ...
    - Building a CodeIgniter Custom Library with M...
    - Building an E-mini Trading System Using PHP ...
    - Completing the MySQL Class with Method Chain...
    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek