5 Questions
What attribute is used to specify which content-type to use when submitting an HTML form for file upload?
enctype
Which file type formats are allowed for image uploads?
PNG
What are the allowed file type formats for audio uploads?
MP3
Which of the following are valid video file types for uploading?
MP4
What file type is allowed for PDF uploads?
Study Notes
Uploading Files
- Configure the "php.ini" file to enable file uploads by setting
file_uploads=on
. - The "php.ini" file can also be configured to upload files larger than 2MB by changing settings.
Creating the HTML Form
- Use the
enctype="multipart/form-data"
attribute in the form to specify the content type.
Uploading the File PHP Script
- Step 1: Check if the directory (uploaded) folder exists, and create it if it doesn't.
-
is_dir
function checks if a filename is a directory, andmkdir
function creates a directory.
Checking File Existence
- Step 2: Check if the file already exists in the "uploaded" folder, and display an error message if it does.
Checking File Size
- Step 3: Check if the file size exceeds 2MB, and display an error message if it does.
Checking File Types
- Step 4: Check the file type and allow only specific types:
- Image files: JPG, JPEG, PNG, and GIF
- Audio files: MP3 and OGG
- Video files: MP4, AVI, MOV, 3GP, and MPEG
- PDF files: Only PDF files are allowed.
Uploading the File
- Step 4: If all checks pass, upload the file to the "uploaded" folder using the
move_uploaded_file
function.
This quiz covers the configuration of php.ini file and the steps to upload a file in PHP, including checking directory existence and file size.
Make Your Own Quizzes and Flashcards
Convert your notes into interactive study material.
Get started for free