Podcast
Questions and Answers
What attribute is used to specify which content-type to use when submitting an HTML form for file upload?
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?
Which file type formats are allowed for image uploads?
What are the allowed file type formats for audio uploads?
What are the allowed file type formats for audio uploads?
Which of the following are valid video file types for uploading?
Which of the following are valid video file types for uploading?
Signup and view all the answers
What file type is allowed for PDF uploads?
What file type is allowed for PDF uploads?
Signup and view all the answers
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.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
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.