PHP Questions & Answers – Image Uploading Ability

This set of PHP Multiple Choice Questions & Answers (MCQs) focuses 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
View Answer

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

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

Answer: a
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.
advertisement
advertisement

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
View Answer

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

Answer: c
Explanation: This is a special comment that provides information about a class, property, or method.
Sanfoundry Certification Contest of the Month is Live. 100+ Subjects. Participate Now!

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()
View Answer

Answer: b
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 _________
a) UPLOAD_ERR_OK
b) UPLOAD_NO_ERR
c) UPLOAD_ERR_NO_OK
d) UPLOAD_ERR
View Answer

Answer: a
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.
advertisement

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
View Answer

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

Answer: c
Explanation: If the path exists, is_dir() returns TRUE; otherwise, it returns FALSE.
advertisement

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
View Answer

Answer: a
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 1000+ Multiple Choice Questions and Answers on PHP.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.