250+ TOP MCQs on PHP Image Uploading Ability and Answers

PHP Multiple Choice Questions on “Image Uploading Ability”.

1. Before you can start processing images with PHP, you must first add the ability to upload images to your administrative form on ________
a) .htaccess
b) function.inc.php
c) index.php
d) admin.php

Answer: d
Clarification: 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 __________
a) text
b) text/file
c) multipart/form-data
d) multimedia/form-data

Answer: c
Clarification: 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.
a) $_FILES
b) $_DOCS
c) $_DOCUMENTS
d) $_FOLDERS

Answer: a
Clarification: 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 __________
a) imagehandler.inc.php
b) images.inc.php
c) handler.inc.php
d) imghandler.inc.php

Answer: b
Clarification: 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 _________
a) /*
b) //*
c) /**
d) /*/

Answer: c
Clarification: 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.
a) divide()
b) list()
c) break()
d) indi()

Answer: b
Clarification: The list() function allows you to create named variables for each array index as a comma-separated list.

  250+ TOP MCQs on PHP Object Tools and Answers

7. Before you try to process the file, you need to make sure that your $err value is equivalent to _________
a) UPLOAD_ERR_OK
b) UPLOAD_NO_ERR
c) UPLOAD_ERR_NO_OK
d) UPLOAD_ERR

Answer: a
Clarification: 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.
a) $load_dir
b) $load
c) $save
d) $save_dir

Answer: d
Clarification: // 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?
a) path_dir()
b) path()
c) is_dir()
d) path_dir()

Answer: c
Clarification: 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

Answer: a
Clarification: If you needed to change the size of your images, you can change the dimensions using the above instantiation of ImageHandler.

 

 

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top