Which PHP superglobal is used to access uploaded files?
Analysis & Theory
`$_FILES` is a PHP superglobal that holds information about uploaded files.
Which HTML attribute must be added to the form to enable file upload?
C
enctype='multipart/form-data'
Analysis & Theory
The form must have `enctype='multipart/form-data'` to handle file uploads.
Which function is used to move an uploaded file to a permanent location?
Analysis & Theory
`move_uploaded_file()` moves an uploaded file from a temporary directory to a permanent one.
Where does PHP temporarily store uploaded files before moving them?
C
In a temporary directory on the server
Analysis & Theory
Uploaded files are temporarily stored in a temp directory on the server, accessible via `$_FILES['file']['tmp_name']`.
How do you check for upload errors in PHP?
A
Using `$_FILES['file']['size']`
B
Using `$_FILES['file']['error']`
C
Using `$_FILES['file']['tmp']`
D
Using `$_FILES['file']['name']`
Analysis & Theory
`$_FILES['file']['error']` contains the error code for the file upload process.
What does error code `UPLOAD_ERR_OK` (value 0) mean?
C
File uploaded successfully
Analysis & Theory
Error code 0 (`UPLOAD_ERR_OK`) indicates the file uploaded without any errors.
Which `$_FILES` property contains the original name of the uploaded file?
Analysis & Theory
`$_FILES['file']['name']` contains the original name of the uploaded file from the client.
What PHP setting limits the maximum file upload size?
Analysis & Theory
`upload_max_filesize` in php.ini controls the maximum size for file uploads.
What happens if the uploaded file exceeds the limit in `upload_max_filesize`?
A
The file is uploaded anyway
B
An error code is set in `$_FILES['file']['error']`
C
PHP compresses the file
D
The browser handles the error
Analysis & Theory
If the file exceeds the maximum size, PHP sets an error code in `$_FILES['file']['error']`.
Which of the following is important for secure file uploads?
A
Checking file size only
B
Validating file type and extension
C
Disabling `enctype` in the form
Analysis & Theory
For security, always check the file extension and MIME type to avoid malicious uploads.