When uploading files to the web server using <input type="file" />, the HTML form has to fulfill two requirements:
Without these settings, the file upload does not work. It also does not work if the following information is missing from php.ini: file_uploads = On But if it does, retrieving information about the file is quite easy: In the (superglobal) array $_FILES, you can find the file upload form field under its name. Then, the following subkeys provide further information about the uploaded file:
Displaying Information About Uploaded Files (upload.php; excerpt)<?php if (isset($_POST['Submit']) && isset($_FILES ['File'])) { printf('<p>Error: %s<br /> Original name: %s<br /> File size: %s<br /> Temporary name: %s<br /> MIME type: %s</p>', $_FILES['File']['error'], $_FILES['File']['name'], $_FILES['File']['size'], $_FILES['File']['tmp_name'], $_FILES['File']['type'] ); } else { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <input type="file" name="File" /> <input type="submit" name="Submit" value="Submit form" /> </form> <?php } ?> The preceding code outputs the available file information (see Figure 4.4). Figure 4.4. Information about the uploaded file.
|