As you probably know, the $_FILES superglobal array available in PHP allows you to retrieve all the information related to a specific file uploading process, including the MIME type and size, its temporary denomination, etc. Thus, based upon the capabilities of this useful array, Iím going to modify the script that I built in the previous article of this series so it can use the array in question to display detailed information about a particular file upload on the browser.
That being explained, please take some time to examine the signature of the improved file uploading script, which now looks like this:
// basic example on uploading a file to the server via HTTP and displaying information on it
// 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!';
As you can see, understanding the logic implemented by the above file uploading script is actually a no-brainer process that can be tackled with minor problems. In this specific case, the script uses a few elements included into the previously mentioned $_FILES PHP array in order to retrieve useful information about a particular file uploading process.
Whatís more, once a targeted file has been successfully uploaded to the web server, the script in question echoes all the data related to this procedure to the browser, including the client name of the pertinent file and other relevant details, such as its MIME type and size in bytes, and its temporary name as well.
Therefore, based on the recently improved logic of the previous file uploading script, itís quite easy to retrieve detailed information on a specific file. For instance, say that I just uploaded a sample ďtest.docĒ file to the web server, which would produce the following result:
The target file was successfully uploaded! Name of uploaded file: test.doc. MIME type of uploaded file: application/ms-word. Size of uploaded file: 19968 bytes. Temporary name of uploaded file: C:uploaded_filesphp135.tmp
Name of uploaded file: test.doc.
MIME type of uploaded file: application/ms-word.
Size of uploaded file: 19968 bytes.
Temporary name of uploaded file: C:uploaded_filesphp135.tmp
That was pretty useful, right? Iím not saying that the $_FILES superglobal array is going to change your life as a PHP developer, but you must admit it works pretty well when it comes to getting meaningful information regarding a specific file uploading process.
All right, at this point I'll assume that you've already grasped how to use the aforementioned $_FILES PHP array to display all the data related to a particular file upload. So, whatís the next step to take?
Well, in the last section of this tutorial, Iím going to list the complete source code of this improved file uploading PHP application, including the corresponding upload web form and the modified script that you learned a few lines before so you can copy it and paste it directly into your code editor for testing purposes.
As I said earlier, this process will be done in the following section, so jump forward and keep reading.
blog comments powered by Disqus