Skip to Content
Mastering PHP 7
book

Mastering PHP 7

by Branko Ajzele
June 2017
Intermediate to advanced
536 pages
9h 49m
English
Packt Publishing
Content preview from Mastering PHP 7

File uploads

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"] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning PHP 7

Learning PHP 7

Antonio L Zapata (GBP)
Upgrading to PHP 5

Upgrading to PHP 5

Adam Trachtenberg

Publisher Resources

ISBN: 9781785882814Supplemental Content