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">
<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="20000" />
<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!';
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.
blog comments powered by Disqus