PHP
  Home arrow PHP arrow Page 2 - 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

    Dell PowerEdge Servers

    Retrieving Information on Selected Files with a PHP 5 File Uploader - Reintroducing a previous hands-on example
    (Page 2 of 4 )

    An excellent way to demonstrate how to improve the logic of the file uploading script developed in the preceding article of the series is to list the respective definitions of its two source files, so you can recall how they were created on that specific occasion.

    That being said, here’s is how the mentioned source files looked, so study them in detail:

    (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="20000" />

    <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!';

    }

    else{

    echo 'Error uploading target file!';

    }

    }


    As I explained before, the above file uploading application is comprised of two basic source files. The first one is responsible for creating a basic file uploading web form and the last one takes up the file selected by the user and implements the logic necessary for moving it from a temporary directory in the web server to its final location. In this case, the upload directory is located at C:uploaded_files, and it’s only valid for Windows users, but this option can be changed to work with a different operating system.

    So far, so good. At this point, I will assume that you’re familiar with the source code that I used to perform file uploads with PHP. Thus, it’s time to see how to introduce some modifications to the previous script.

    Given that the $_FILES superglobal array provides complete information on a file uploading operation, I’m going to use some of its additional elements to display accurate data about this process, including the size and MIME type, the size of the file being uploaded, and so forth.

    To see how these minor improvements will be incorporated into the prior file uploading application, jump into the next section 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

    - 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