In consonance with the concepts deployed in the prior section, below I listed the two source files that make up this PHP-driven file uploading application, including the pertinent web form and the script that I modified earlier.
That being said, hereís how these source files look:
(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">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Uploading files with PHP</title>
font: bold 16pt Arial, Helvetica, sans-serif;
font: normal 10pt Arial, Helvetica, sans-serif;
border: 1px solid #666;
<h1>Uploading files with PHP</h1>
<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>
(definition of 'upload_file.php' file)
// set upload directory (for Windows users)
// set destination of uploaded file
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 />';
echo 'Error uploading target file!';
There you have it. With the two source files listed above at your disposal, you shouldnít have major problems developing your own PHP file upload application, even though its current state is quite primitive.
However, if youíre learning the basic concepts of how to implement a simple file uploading mechanism with PHP, the entirety of the code samples included in this tutorial should be good enough to fit your needs for now.
In this second chapter of the series, you learned how to use the $_FILES superglobal array included with PHP in order to create a simple file uploading application that is also capable of displaying relevant information about an uploaded file.
As you saw earlier, utilizing this useful array isnít rocket science. So in consequence, you shouldnít have major problems understanding how to use it when building your own file upload applications.
In the next tutorial of the series, things will become more interesting because Iím going to teach you how to incorporate an effective error handling module to the previous PHP script, which will come in handy when tracking the eventual failures that might occur during a particular file uploading process.
Now that youíre aware of the topics that will be discussed in the upcoming article, you wonít want to miss it!
blog comments powered by Disqus