Display the details of the uploaded file: printf(”Uploaded

Display the details of the uploaded file: printf(”Uploaded File Details

“); printf(”Name: %s
“, $HTTP_POST_FILES[”userfile”][”name”]); printf(”Temporary Name: %s
“, $HTTP_POST_FILES[”userfile”][”tmp_name”]); printf(”Size: %s
“, $HTTP_POST_FILES[”userfile”][”size”]); printf(”Type: %s

“, $HTTP_POST_FILES[”userfile”][”type”]); Copy the uploaded file to the C:temp directory: if (copy($HTTP_POST_FILES[”userfile”][”tmp_name”], “c:/temp/”.$HTTP_POST_FILES[”userfile”][”name”])) { printf(”File successfully copied“); } else { printf(”Error: failed to copy file“); } ?> Sometimes we may want to set a limit on the size of file that can be uploaded to the system. This can be done by checking the size of the file in the PHP script. For example, to accept files only with a size of one megabyte or less, we could modify upload.php as follows: if ($HTTP_POST_FILES[”userfile”][”size”] > 1024*1024) { printf(” Error: File size is greater than one megabyte“); exit; } if (copy($HTTP_POST_FILES[”userfile”][”tmp_name”], “c:/temp/”.$HTTP_POST_FILES[”userfile”][”name”])) { printf(”File successfully copied“); } else { printf(”Error: failed to copy file“); } The PHP directive upload_max_filesize (default value 2Mb) can be used to specify the max size of the uploaded file that will be handled by PHP. Any upload files greater than this size will not be uploaded by PHP. PHP provides utility functions for handling files uploaded via the HTTP POST method: . is_uploaded_file() returns true, if the file (filename) was uploaded via the HTTP POST method. . move_uploaded_file() copies the uploaded file filename to destination. If the file is not a valid uploaded file, then the function doesn’t do anything. The function returns true on success. Page 251

Hint: If you are looking for very good and affordable webspace to host and run your tomcat hosting application check Virtualwebstudio tomcat web hosting provider

Comments are closed.