PHP
  Home arrow PHP arrow Page 2 - Building File Uploaders with PHP 5
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? 
PHP

Building File Uploaders with PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2008-03-19


    Table of Contents:
  • Building File Uploaders with PHP 5
  • Implementing file uploads with PHP: the $_FILES superglobal array
  • Building a simple file uploading form
  • Processing a file upload with PHP

  • 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


    Building File Uploaders with PHP 5 - Implementing file uploads with PHP: the $_FILES superglobal array
    ( Page 2 of 4 )

    It's practically impossible to cover file uploads in PHP 4/5 without examining one of the key elements involved in this process in detail. Yes, you guessed right! In this case, I'm talking about the $_FILES superglobal PHP array (or its equivalent in earlier versions, $HTTP_POST_FILES), which handles every parameter created by PHP with precision, such as when a file is being uploaded to the server via the HTTP protocol.

    But it's time to get rid of this rather boring theory and see how the $_FILES array stores all the information related to an uploaded file. The following list shows each element that makes up this array along with a brief description of what it does (notice that the explanations assume that the web form used to upload a file contains a field named "userfile"):


    $_FILES['userfile']['name'] (Specifies the original name of the file being uploaded on the client computer).

    $_FILES['userfile']['type'] (Specifies the MIME type of the file being uploaded, for instance, "image/jpeg").

    $_FILES['userfile']['size'] (Indicates the size in bytes of the file being uploaded).

    $_FILES['userfile']['tmp_name'] (Indicates the temporary name used by the web server to store the uploaded file).

    $_FILES['userfile']['error'] (Specifies the error code associated with a specific file upload).


    Now that I have listed the elements that make up the $_FILES superglobal array, you can see more clearly, based on the above descriptions, that PHP provides all the parameters required to perform file uploads with minor hassles.

    It's important to stress that the array in question also includes an element that stores an error number associated with the file uploading process, which means that it's pretty simple to implement the logic necessary to handle these eventual errors. But I'm getting ahead of myself, since this topic will be covered in an upcoming tutorial of the series.

    So, at this point, I have provided you with a quick overview of the different elements included in the $_FILES superglobal array, which stores all the information related to a specific file uploading process. But you're probably wondering how this array can be used to perform a file upload within a PHP script, right?

    Well, first it's necessary to build a simple front-end that permits users to select a particular file in the client machine, and then upload it to the web server. Thus, considering this requirement, in the section to come I'm going to show you how to create a simple web form that will perform this task in a straightforward way.

    Naturally, to see how this file uploading form will be coded, you'll have to click on the link below and keep reading.



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

       

    PHP ARTICLES

    - 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
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    Stay green...Green IT