June 2017
Intermediate to advanced
536 pages
9h 49m
English
Uploading files is a common functionality to many PHP applications. So common that PHP provides a convenient global $_FILES variable we can use to access uploaded files, or errors behind the file upload tries.
Let's take a look at the following simple file upload form:
<form method="post" enctype="multipart/form-data"> <input type="file" name="photo" /> <input type="file" name="article" /> <input type="submit" name="submit" value="Upload" /></form>
In order for PHP to pick up the files, we need to set the form method value to post, and enctype to multipart/form-data. Once submitted, PHP will pick it up and fill in the $_FILES variable appropriately:
array(2) { ["photo"] => array(5) { ["name"] => string(9) "photo.jpg" ["type"] ...