Prev | Current Page 464 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"


394 CHAPTER 15 ?–  HANDL ING F ILE UPLOADS
??? UPLOAD_ERR_PARTIAL: A value of 3 is returned if a file is not completely uploaded.
This might happen if a network error occurs that results in a disruption of the
upload process.
??? UPLOAD_ERR_NO_FILE: A value of 4 is returned if the user submits the form
without specifying a file for upload.
A Simple Example
Listing 15-1 (uploadmanager.php) implements the class notes example referred to
throughout this chapter. To formalize the scenario, suppose that a professor invites
students to post class notes to his Web site, the idea being that everyone might have
something to gain from such a collaborative effort. Of course, credit should nonetheless
be given where credit is due, so each file upload should be renamed to the last
name of the student. In addition, only PDF files are accepted.
Listing 15-1. A Simple File-Upload Example

Last Name:


Class Notes:




/* Set a constant */
define ("FILEREPOSITORY","/home/www/htdocs/class/classnotes/");
/* Make sure that the file was POSTed. */
if (is_uploaded_file($_FILES['classnotes']['tmp_name'])) {
/* Was the file a PDF? */
if ($_FILES['classnotes']['type'] != "application/pdf") {
echo "

Class notes must be uploaded in PDF format.


Pages:
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476