This set of PHP multiple choice questions and answers focuses on image uploading ability. It will be useful for anyone learning PHP Basics and Fundamentals.
1. Before you can start processing images with PHP, you must first add the ability to upload images to your administrative form on ___.
Explanation: To do this, you’ need to add a file upload input to your administrative form.
2. When you’re uploading files you need to set the enctype of the form to ___.
Explanation: Set the enctype of the form to multipart/form-data, which can accept files and standard form values.
3. To check whether a file was uploaded, you look in the ___ superglobal array.
Explanation: Whenever a file is uploaded via an HTML form, that file is stored in temporary memory and information about the file is passed in the $_FILES superglobal.
4. To make the ImageHandler class portable you should create a separate file for it called ___.
Explanation: You save this file in the inc folder (full path: /xampp/htdocs/simple_blog/inc/images.inc.php).
5. DocBlocks are indicated by opening a comment using ___.
Explanation: This is a special comment that provides information about a class, property, or method.
6. To process the file, you need to break the array from $_FILES into individual values. You can do this using the ___ function.
Explanation: The list() function allows you to create named variables for each array index as a comma-separated list.
7. Before you try to process the file, you need to make sure that your $err value is equivalent to ___.
Explanation: When you’re dealing with files uploaded through an HTML form, you have access to a special constant called UPLOAD_ERR_OK that tells you whether a file uploaded successfully.
8. You use the $_SERVER superglobal and your ___ property to create your path to check.
Explanation: // Determines the path to check
$path = $_SERVER[‘DOCUMENT_ROOT’] . $this->save_dir;
9. Which function do you have to use to check whether the $path you’ve stored exists?
Explanation: If the path exists, is_dir() returns TRUE; otherwise, it returns FALSE.
10. Which one of the following is true about the following line – $obj = new ImageHandler(‘/images/’, array(400, 300));
a) This snippet sets the maximum dimensions allowed to 400 pixels wide by 300 pixels high.
b) This snippet sets the minimum dimensions allowed to 300 pixels wide by 400 pixels high.
c) This snippet sets the minimum dimensions allowed to 400 pixels wide by 300 pixels high.
d) This snippet sets the maximum dimensions allowed to 300 pixels wide by 400 pixels high.
Explanation: If you needed to change the size of your images, you can change the dimensions using the above instantiation of ImageHandler
Sanfoundry Global Education & Learning Series – PHP Programming.
To practice all questions on PHP Programming, here is complete set of 250+ Multiple Choice Questions and Answers on PHP.