PHP Solutions
Chapter 6
The theme of this chapter is uploading files.
Note: None of these scripts will actually upload files.
Solution Index
- Inspecting the
$_FILES
array - Showing the array produced when using the
$_FILES
superglobal.
Upload anything. The script has no handling, so the file is dumped immediately. - PHP Solutions 6-1
- Basic file upload
Uploads the file to a specific folder - PHP Solutions 6-2
- Making filenames web-safe
the script now replaces empty spaces in the file name with an underscore usingstr_replace
. - PHP Solutions 6-3
- Setting a size limit and displaying outcome
The size limit is 3000 bytes. The outcomes tell whether the file is too large, was not sent, or uploaded correctly. - PHP Solutions 6-4
- Restricting upload file types
Restricts the file types to .gif, .jpg, .jpeg, .png. - PHP Solutions 6-5
- Using a timestamp to create a unique name
Checks to see if the new file shares a name with one already in the folder, if so, it prefixes a timestamp to the filename. - PHP Solutions 6-6
- Creating user-specific upload folders
Checks to see if a directory with said username exists, if it doesn't, it makes it.(Username is hardcoded.) - PHP Solutions 6-7
- Processing a multiple file upload
Adding a second upload field and processing both simultaneously.