0
0
PHPprogramming~5 mins

$_FILES for file uploads in PHP - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the $_FILES superglobal in PHP?

The $_FILES superglobal is used to collect information about files uploaded via an HTML form. It stores details like the file name, type, size, temporary location, and any upload errors.

Click to reveal answer
beginner
Name the main keys inside the $_FILES['input_name'] array for an uploaded file.
  • name: Original file name on the client machine
  • type: MIME type of the file
  • tmp_name: Temporary filename on the server
  • error: Error code associated with the upload
  • size: Size of the uploaded file in bytes
Click to reveal answer
beginner
What does an error value of 0 mean in $_FILES['input_name']['error']?

An error value of 0 means the file uploaded successfully without any errors.

Click to reveal answer
beginner
How do you access the temporary file path of an uploaded file named profile_pic?

You access it with $_FILES['profile_pic']['tmp_name']. This is the path where PHP stores the uploaded file temporarily before you move it.

Click to reveal answer
beginner
Why should you use move_uploaded_file() after receiving a file via $_FILES?

Because the uploaded file is stored in a temporary location, move_uploaded_file() safely moves it to a permanent directory on your server. This prevents the file from being deleted after the script ends.

Click to reveal answer
Which $_FILES key holds the original name of the uploaded file?
Atmp_name
Bsize
Cname
Derror
What does $_FILES['file']['error'] === 4 indicate?
AFile size exceeded limit
BNo file was uploaded
CPartial upload
DUpload successful
Which PHP function should you use to move an uploaded file to a permanent location?
Amove_uploaded_file()
Brename()
Ccopy()
Dunlink()
Where does PHP store uploaded files before you move them?
AIn the <code>$_POST</code> array
BIn the <code>$_GET</code> array
CIn the user's browser cache
DIn a temporary folder on the server
What type of HTML form attribute is required to upload files?
Aenctype="multipart/form-data"
Bmethod="get"
Caction="upload.php"
Dtarget="_blank"
Explain how PHP's $_FILES array works when a user uploads a file through a form.
Think about the journey of the file from the user's computer to your server.
You got /5 concepts.
    Describe the steps to safely handle a file upload in PHP using $_FILES.
    Focus on safety and correctness when saving the uploaded file.
    You got /5 concepts.