File Uploading with PHP

In this article we look at how to upload files using PHP. This technique can be extremely useful, and is used on many sites for example, in content management systems or forums which allow the user to upload an image to represent them.

In this standalone tutorial, we start by looking at how to create the HTML form required to upload files. We then look at how to upload a single file, and then expand the code to allow multiple files to be uploaded. Finally we look at some useful file handling commands, and how to read the dimensions from an image file.

This is suitable for MX and MX 2004 users, from beginners upwards.

$2.79
- OR -

Overview

Table of Content:

  • PHP INI File Settings
      < LI>
    • upload_tmp_dir
    • upload_max_filesize
    • post_max_sizeLI>
  • Creating the HTML
    • Configuring the Form Properties
    • Adding a File Field
    • Adding Hidden Fields
  • PHP Code to upload a file
    • The PHP $_FILES array
    • Destination Directory – Permissions
    • A working example
    • File Upload Code with Error Checking
  • Uploading Multiple Files
  • Useful File Commands
    • Deleting a file
    • Reading the Size of a File
    • Reading a Directory
  • Gathering Information about an uploaded file
    • Reading a files extension
    • Finding the dimensions an image
  • Summary 

Gareth Downes-Powell

Gareth Downes-PowellGareth has a range of skills, covering many computer and internet related subjects. He is proficient in many different languages including ASP and PHP, and is responsible for the setup and maintenance of both Windows and Linux servers on a daily basis.


In his daily web development work he uses the complete range of Macromedia software, including Dreamweaver MX, Flash MX, Fireworks MX and Director to build a number of websites and applications. Gareth has a close relationship with Macromedia, and as a member of Team Macromedia Dreamweaver, he has worked closely in the development of Dreamweaver, and was a beta tester for Dreamweaver MX.


On a daily basis he provides support for users in the Macromedia forums, answering questions and providing help on a range of different web related subjects. He has also written a number of free and commercial extensions for Dreamweaver MX, to further extend its capabilities using its native JavaScript API’s or C++.


As a web host, Gareth has worked with a range of different servers and operating systems, with the Linux OS as his personal favourite. Most of his development work is done using a combination of Linux, Apache and MySQL and he has written extensively about setting up this type of system, and also running Apache and MySQL under Windows.

See All Postings From Gareth Downes-Powell >>

Reviews

File uploading tutorail problem

December 29, 2003 by Faisal Khashouf

Hi,

I tried the steps as descriped in tutorial. when I press submit button I get weird url on the top, and msg on my ie saying cannot dispaly page (I am using PHP_TYPE at the action for the form so my action string looks exactly like this ---   <?php echo $_SERVER['PHP_TYPE']; ?>

Now anyhelp could be appriceated .... I am using PHP/MYSQL/Localhost on WinXP, with DWMX.

The Article I am applying is called :File Uploading with PHP, by  Gareth Downes-Powell.

 

Thanks

RE: File uploading tutorail problem

December 29, 2003 by Martha Graham

Please post this question in the forum, especially created for this tutorial: http://www.dmxzone.com/forum/default.asp?NewsId=5561

Martha Graham
DMXzone.com

You must me logged in to write a review.