13.09.2016 Views

PHP and MySQL Web Development 4th Ed-tqw-_darksiderg

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

432 Chapter 19 Interacting with the File System <strong>and</strong> the Server<br />

Figure 19.1 The HTML form used for this file upload has different fields<br />

<strong>and</strong> field types from those of a normal HTML form.<br />

As you can see, the form has a box where the user can enter a filename or click the<br />

Browse button to browse files available to him locally.We look at how to implement this<br />

form shortly.<br />

After entering a filename, the user can click Send File, <strong>and</strong> the file will be uploaded<br />

to the server, where a <strong>PHP</strong> script is waiting for it.<br />

Before we dive into the file uploading example, it is important to note that the<br />

php.ini file has five directives that control how <strong>PHP</strong> will work with file uploading.These<br />

directives, their default values, <strong>and</strong> descriptions are shown in Table 19.1.<br />

Table 19.1 File Upload Configuration Settings in php.ini<br />

Directive Description Default Value<br />

file_uploads Controls whether HTTP file uploads are allowed. On<br />

Values are On or Off.<br />

upload_tmp_dir Indicates the directory where uploaded files will NULL<br />

temporarily be stored while they are waiting to<br />

be processed. If this value is not set, the system<br />

default will be used.<br />

upload_max_filesize Controls the maximum allowed size for uploaded 2M<br />

files. If a file is larger than this value, <strong>PHP</strong> will<br />

write a 0 byte placeholder file instead.<br />

post_max_size Controls the maximum size of POST data that 8M<br />

<strong>PHP</strong> will accept.This value must be greater than<br />

the value for the upload_max_filesize<br />

directive, since it is the size for all of the post<br />

data, including any files to be uploaded.

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

Saved successfully!

Ooh no, something went wrong!