Prev | Current Page 465 | Next

W. Jason Gilmore

"Beginning PHP and MySQL: From Novice to Professional"

";
} else {
/* move uploaded file to final destination. */
$name = $_POST['name'];
CHAPTER 15 ?–  HANDL ING F ILE UPLOADS 395
$result = move_uploaded_file($_FILES['classnotes']['tmp_name'],
FILEREPOSITORY."/$name.pdf");
if ($result == 1) echo "

File successfully uploaded.

";
else echo "

There was a problem uploading the file.

";
} #endIF
} #endIF
?>
?– Caution Remember that files are both uploaded and moved under the guise of the Web server
daemon owner. Failing to assign adequate permissions to both the temporary upload directory and the
final directory destination for this user will result in failure to properly execute the file-upload procedure.
While it??™s quite easy to manually create your own file-upload mechanism, the
HTTP_Upload PEAR package truly renders the task a trivial affair. This package is the
topic of the next section.
Taking Advantage of PEAR: HTTP_Upload
While the approaches to file uploading discussed thus far work just fine, it??™s always
nice to hide some of the implementation details by using a class. The PEAR class
HTTP_Upload satisfies this desire quite nicely. It encapsulates many of the messy aspects
of file uploading, exposing the information and features you??™re looking for via a
convenient interface. This section introduces HTTP_Upload, showing you how to take
advantage of this powerful, no-nonsense package to effectively manage your site??™s
upload mechanisms.


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