In this assignment you need to handle the file with the image you are uploading to the web server. When you used the arrays $_POST in your PHP script that handles the information passed by the image input form, you may notice that information about the file name entered into the input element of the type file is not there. This happens because in PHP there is a special array that contains this kind of information. This is the $_FILES array. This array is slightly different from the arrays $_GET and $_POST we have considered. Since the browser sends several pieces of information about each file you uploading to the server (such as name, size, type, etc) this array is a 2 dimensional array. Both dimensions are string-indexed. The first dimension index is just the name of file input element. For example, if in my HTML form I have
<input type="file" name="my_image" />then in my PHP script I would access info about the file as
| Index | Description |
|---|---|
| name | The original name of the file on the client machine. |
| type | The mime type of the file, if the browser provided this information. An example would be "image/gif". This mime type is however not checked on the PHP side and therefore don't take its value for granted. |
| size | The size, in bytes, of the uploaded file. |
| tmp_name | The temporary filename of the file in which the uploaded file was stored on the server. |
| error | The error code associated with this file upload. This element was added in PHP 4.2.0 |
move_uploaded_file($_FILES["my_image"]["tmp_name"], "img/" . basename($_FILES["my_image"]["name"]));If the file has been successfully moved the function returns true and it returns false otherwise. You can use the return value to determine what kind of message to print back to the user. Please find more information about handling file uploads on the PHP site.
The actual assignment for this homework would be the following. Create a PHP script that takes all the data sent by the input form and:
Please don't forget to use method POST for the <form> element and also set
enctype attribute to