Wouldn't it be nice if you could upload files from a local machine to the server using the directory navigator you just created? PHP offers an easy way to put this functionality into your applications you can let users upload files. The form tag's enctype attribute, which is usually omitted when creating a normal from, also needs to be Here's a sample upload from.
The action attribute of the form should point to a php script that will handle the uploaded file. You don't have to provide the second text input tag unless you want to let users choose a different filename with which the uploaded file will be stored on the server.
Once a file is uploaded, the following variable values become available for use via the superglobal
$_FILES array:
Variable
$_FILES[userfile]
$_FILES[userfile][name]
$_FILES[userfile][size]
$_FILE[userfile][type]
Description
The array in $_FILES that contains the other array values
The original path and the filename of the uploaded file
The size of the uploaded file in bytes
The type of the file (if the browser provides the information)
Suppose a user has just uploaded a 20,000-byte ZIP file, docs\projects.zip, using this form. These variables now contain the following:
$_FILES[userfile] [tmp_name]: The path to the file in the temporary directory (as set in php.ini) plus the temporary filename in the format “php-### format (where ***** is a number which is automatically generated by PHP), for example, /tmp/php-512”.
$_FILES[userfile] [name]: “C:\docs\projects.zip”
$_FILES[userfile] [size]: 20000
$_FILES[userfile] [type]: “application/x-zip-compressed”
You can set these values to normal variables if you like, as shown here:
//get the userfile particulars
$userfile_name = $_FILES[‘userfile'][‘name']; $userfile_tmp_name = $_FILES[‘userfile'][‘tmp_name']; $userfile_size = $_FILES[‘userfile'][‘size']; $userfile_type = $_FILES[‘userfile'][‘type'];
if (isset($_ENV[‘WINDIR'])) {
anlbeolqu
$userfile = str_replace(“\\\\”,”\\”, $_FILES[‘userfile'][‘name']);
The uploaded file is saved in the temporary directory set in php.ini and destroyed at the end of the request, so you need to copy it to somewhere else. For security reasons, it's recommended that you use the move_uploaded_file() function instead of the copy() function: