PHP
  Home arrow PHP arrow Page 2 - Creating an Error Handling Module for ...
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

Creating an Error Handling Module for a PHP 5 File Uploader
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2008-04-02

    Table of Contents:
  • Creating an Error Handling Module for a PHP 5 File Uploader
  • Performing file uploads without checking errors
  • Creating an effective error handling module
  • 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

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Creating an Error Handling Module for a PHP 5 File Uploader - Performing file uploads without checking errors
    (Page 2 of 4 )

    If you're anything like me, then you'll feel curious about how to include an effective error checking mechanism inside the file uploading script that I built in the preceding article of this series. Thus, let me quickly show you the complete source code of this application, including the corresponding web form that permits users to browse files in their respective client machines.

    Here are the source files that comprise the file uploading application:


    (definition of 'upload_form.htm' file)


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

    <title>Uploading files with PHP</title>

    <style type="text/css">

    body{

    padding: 0;

    margin: 0;

    background: #fff;

    }

    h1{

    font: bold 16pt Arial, Helvetica, sans-serif;

    color: #000;

    text-align: center;

    }

    p{

    font: normal 10pt Arial, Helvetica, sans-serif;

    color: #000;

    }

    form{

    display: inline;

    }

    #formcontainer{

    width: 50%;

    padding: 10px;

    margin-left: auto;

    margin-right: auto;

    background: #eee;

    border: 1px solid #666;

    }

    </style>

    </head>

    <body>

    <h1>Uploading files with PHP</h1>

    <div id="formcontainer">

    <form enctype="multipart/form-data" action="upload_file.php" method="post">

    <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />

    <p>File to upload <input name="userfile" type="file" />

    <input type="submit" name="send" value="Upload File" /></p>

    </form>

    </div>

    </body>

    </html>



    (definition of 'upload_file.php' file)

     

    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'll possibly recall, the two source files listed above are all that you need to build a simple file uploading application with PHP that has the capacity to display relevant data about the file uploaded. Not too difficult to grasp, right?

    Well, at this point, I showed you how to create a basic file uploading system by using a couple of simple source files. So the next thing that I'm going to teach you will be how to incorporate an effective error checking module into the system in question, which will extend its existing functionality.

    Want to see how this will be done? Great! Click on the link below and keep reading.

    More PHP Articles
    More By Alejandro Gervasio


       · File uploads, as other tasks performed by users, require to check input data....
     

       

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