Free Programming Books
Free download ebooks on computer and programming | |||
Free PHP/MySQL ebook "Beginning PHP 5 and MySQL: From Novice to Professional" Sample ChapterBeginning PHP 5 and MySQL... Download chapterFree download Chapter 13: Handling File Uploads Beginning PHP 5 and MySQL: From Novice to Professional offers a comprehensive introduction to two of the most popular open source technologies on the planet: the PHP scripting language and the MySQL database server. Whether you're a newcomer searching for a thorough introduction to these popular technologies, or a seasoned developer in need of a comprehensive reference, this book is for you. You will be exposed to the core features of both technologies, as well as gain valuable insight into how the technologies are combined to create dynamic, data-driven web applications. You'll also learn about many undocumented features of the most recent versions. The first part of the book is devoted to PHP's foundational features, with emphasis on features new to PHP 5, like improved object-oriented support, exception handling, SQLite support, SimpleXML, and much more. Other chapters are devoted to basic PHP programming concepts such as variables, datatypes, arrays, string manipulation, and user interaction. You'll also learn about PHP 5's core capabilities, starting with a survey of installation and configuration tasks. Additional chapters cover session handling, LDAP integration, the Smarty templating engine, and Web Services support. The latter part of the book overviews the powerful MySQL database server. You'll learn about the installation and configuration process, datatypes, key security features, and various administration utilities. Next, you'll proceed to learn about PHP's assortment of MySQL functions, supported by dozens of examples depicting the creation and execution of queries. You'll also learn how to perform searches and manage database transactions. Handling File UploadsDESPITE THE HYPE, glory, and often rumors of magical powers bestowed upon it almost from birth, the Web is really nothing more than a global file server. More specifically, it's a global file server farm. And although HTML files of course make up the vast majority of all files transferred via the HTTP protocol, it has become quite commonplace to make Word documents, PDFs, executables, MPEGs, and any number of other file types accessible via the Web. Although FTP has historically been the common means for uploading files to a server, such file transfers are becoming increasingly prevalent via a Web-based interface. In this chapter, you'll learn all about PHP's fileupload handling capabilities. In particular, chapter topics include:
Uploading Files via the HTTP ProtocolThe way files are uploaded via a Web browser was officially formalized in around November 1995, when Ernesto Nebel and Larry Masinter of the Xerox Corporation proposed a standardized methodology for doing so within RFC 1867 (http://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 Internet 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, is considered too inefficient to handle large quantities of binary data such as that which might be uploaded via such a form interface.
<form action="uploadmanager.html" enctype="multipart/form-data" method="post"> Name:<br /> <input type="text" name="name" value="" /><br /> Email:<br /> <input type="text" name="email" value="" /><br /> Homework:<br /> <input type="file" name="homework" value="" /><br /> <p><input type="submit" name="submit" value="Submit Homework" /></p> </form> Understand that this offers only half of the desired result; whereas the file input type and other upload-related attributes standardize the way files are sent to the server via an HTML page, no capabilities are offered for determining what happens once that file gets there! The reception and subsequent handling of the uploaded files is a function of an upload handler, created using some server process, or capable server-side language, like Perl, Java, or PHP. We'll devote the remainder of this chapter to this aspect of the upload process. | |||