PHP
  Home arrow PHP arrow Page 2 - Building File Uploaders with PHP 5
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 
IBM Rational Software Development Conference
 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: 4 stars4 stars4 stars4 stars4 stars / 5
    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:
      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

    Route your faxes to your email inbox. Private, secure fax numbers available from CallWave. Choose your fax number.

    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


       · Uploading files to a server using a web-based interface has always been an...
       · HelloI used scripts as the presented in the article to catch file uploads not from...
       · Hi Gustavo,Thank you for commenting on my PHP article. With reference to your...
       · Thank you for answer. Im sure I've took care about some of the things you mentioned,...
       · Hi again Gustavo,It seems there’s a problem with different settings for PHP 4...
       · ThanksI just do test using a full path as...
       · Thanks for the comments and I hope you can fix up your problem.Regards.
       · I found the solution, I post it here for anybody:The issue was: "there are a...
       · I’m glad to know you found the solution. And surely, it will be useful for other...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - 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

     
    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 4 hosted by Hostway