Home arrow PHP arrow Defining a Custom Function for File Uploaders with PHP 5

Defining a Custom Function for File Uploaders with PHP 5

In the next few lines I’m going to show you how to wrap the file uploading application built in the previous article of the series into a single custom PHP function. This will turn it into a more maintainable and reusable piece of code.

TABLE OF CONTENTS:
  1. Defining a Custom Function for File Uploaders with PHP 5
  2. The full source code of the previous file uploading application
  3. Putting the file uploading script into the “uploadFile()” custom PHP function
  4. Putting the uploadFile() PHP custom function to work
By: Alejandro Gervasio
Rating: starstarstarstarstar / 1
April 09, 2008

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Learning how to implement file uploads with PHP is undoubtedly one of those things that you have to tackle sooner or later, during your life as PHP developer. And if you’re not armed with a decent background on this topic, there’s the possibility that by the time you finish building your first file uploading application, you will have suffered serious hair loss.

However, there’s no need to expect this, since in this series of articles, you’ll find the right pointers to help you start implementing file uploads with PHP 5. And as always, you’ll be provided with copious practical examples that will help you understand this useful topic from a hands-on point of view.

Now that you’ve been introduced to the principal subject of this article series, let me quickly rehash the items that I discussed in the preceding installment, in case you haven’t read it yet. In the course of the mentioned tutorial, I went through the development of a basic error handling module that came in handy for keeping track of all the errors that might occur during a specific file uploading process.

What’s more, the logic implemented by this simple error checking module was built around the functionality provided by the $_FILES super global PHP array, since it uses one of its elements to store different error codes that are associated with a particular file uploading failure. In this way, it was pretty simple to instruct the module in question to throw several exceptions that could be neatly caught by a typical “try-catch()” block.

So far, so good. At this point, I should assume that building an error checking mechanism that is aimed at tracking all the failures that might arise when uploading a selected file to a web server, is now a familiar process to you. Therefore, it’s time to introduce a few other improvements to the pertinent file uploading application that you learned in the previous tutorial.

Let’s continue this educational journey now!



 
 
>>> More PHP Articles          >>> More By Alejandro Gervasio
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: