11.07.2015 Views

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

PHP MySQL - Stilson.net

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

www.it-ebooks.infoC H A P T E R 15• • •Handling File UploadsMost people know that the Web’s HTTP protocol is primarily involved in the transfer of web pages froma server to the user’s browser. However, it’s actually possible to transfer of any kind of file via HTTP,including Microsoft Office documents, PDFs, executables, MPEGs, ZIP files, and a wide range of otherfile types. Although FTP historically has been the standard means for uploading files to a server, filetransfers are becoming increasingly prevalent via a web-based interface. In this chapter, you’ll learn allabout <strong>PHP</strong>’s file upload handling capabilities, including the following topics:• <strong>PHP</strong>’s file upload configuration directives• <strong>PHP</strong>’s $_FILES superglobal array, used to handle file-upload data• <strong>PHP</strong>’s built-in file-upload functions: is_uploaded_file() andmove_uploaded_file()• A review of possible error messages returned from an upload script• An overview of the HTTP_Upload PEAR packageSeveral real-world examples are offered throughout this chapter, providing you with applicableinsight into this topic.Uploading Files via HTTPThe way files are uploaded via a Web browser was officially formalized in November 1995 when ErnestoNebel and Larry Masinter of the Xerox Corporation proposed a standardized methodology for doing sowithin RFC 1867, “Form-Based File Upload in HTML” (www.ietf.org/rfc/rfc1867.txt). This memo,which formulated the groundwork for making the additions necessary to HTML to allow for file uploads(subsequently incorporated into HTML 3.0), also offered the specification for a new Inter<strong>net</strong> media type,multipart/form-data. This new media type was desired because the standard type used to encode“normal” form values, application/x-www-form-urlencoded, was considered too inefficient to handlelarge quantities of binary data that might be uploaded via such a form interface. An example of a fileuploadingform follows, and a screenshot of the corresponding output is shown in Figure 15-1:Name:Email:Class notes:319

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!