HomePHP Creating an Error Handling Module for a PHP 5 File Uploader
Creating an Error Handling Module for a PHP 5 File Uploader
Welcome to the third chapter of the series “Building file uploaders with PHP 5.” Comprised of five approachable tutorials, this series teaches you the fundamentals of constructing file uploading applications with PHP 5. It also complements the corresponding theoretical concepts with numerous hands-on examples. In this third tutorial of the series, I’m going to show you how to incorporate a brand new error checking module into the file uploading PHP script created in the last article.
As with many other topics related to the development of modern web applications, PHP makes file uploading a no-brainer process, even for those programmers who are just starting to familiarize themselves with the basics of this popular language. Fortunately, the intrinsic flexibility of PHP permits us to build file uploading applications using a procedural approach and the object-oriented paradigm. Thus, if you're interested in learning how to implement file uploads by way of a few simple functions and classes, then don't waste more time and start reading this article series now!
Now that you're familiar with the goal of this article series, I'd like to spend a few moments rehashing the topics that were treated in the last article, in case you haven't the chance to read it. In simple terms, I explained how to build a rudimentary file uploading application that was given the ability to display useful information about an uploaded file, including its MIME type and size expressed in bytes, and its temporary name and client names as well.
This capacity was introduced into the script in question via the $_FILES super global array, which provides detailed information on each file uploading process performed with PHP. However, it's fair to highlight an important point regarding the use of this array: it also includes a handy element that stores different error codes when a file has been uploaded to the web server. As you may have guessed, it's possible to use this set of error numbers to implement an efficient error handling module that keeps track of the different failures that might occur during a specific file upload.
It's time to dispose of the preliminaries and learn how to create the aforementioned error processing module in a few easy steps. Let's go!