PHP
  Home arrow PHP arrow Page 3 - Retrieving Information on Selected Fil...
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
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? 
PHP

Retrieving Information on Selected Files with a PHP 5 File Uploader
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 3
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Lose your application development headaches. Start developing and deploying applications with Advantage Database Server today. Download a 30-day trial for Free!

    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


       · In this second chapter of the series, you’ll learn how to use the $_FILES...
       · Great tutorial, iv being trying to develope this code to also include writing the...
       · Thank you for the kind comments on my PHP article. Now, regarding the code you...
     

       

    PHP ARTICLES

    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5
    - Working with Multiple Document Nodes with th...

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway