PHP File Upload Configuration
5 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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 (correct)
  • JPEG (correct)
  • GIF (correct)
  • JPG (correct)
  • What are the allowed file type formats for audio uploads?

  • MP3 (correct)
  • OGG (correct)
  • WAV
  • AAC
  • Which of the following are valid video file types for uploading?

    <p>MP4</p> Signup and view all the answers

    What file type is allowed for PDF uploads?

    <p>PDF</p> 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, and mkdir 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.

    Quiz Team

    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.

    More Like This

    PHP File Handling Quiz
    10 questions

    PHP File Handling Quiz

    FuturisticOrangutan2273 avatar
    FuturisticOrangutan2273
    PHP File Handling: feof() and fwrite() Functions
    7 questions
    PHP Basics and File Extensions
    17 questions
    Use Quizgecko on...
    Browser
    Browser