<form action="upload.php" method="post" enctype="multipart/form-data"> <input type="file" name="file1"><br> <input type="submit" value="upload"><br> <form>
$_FILES
arrayIndex | Description |
'name' | The original name of the uploaded file. |
'size' | The size of the uploaded file in bytes. |
'tmp_name' | The temporary name of the uploaded file on the web server. |
'type' | The MIME type of the uploaded file as sent by the user’s browser. |
'error' | The error code associated with the file. Common values are UPLOAD_ERR_OK (no error), UPLOAD_ERR_INI_SIZE (file was too large), and UPLOAD_ERR_PARTIAL (upload was not completed). |
Function | Description |
---|---|
move_uploaded_file($tmp, $new) |
Moves an uploaded file from its temporary location to a permanent location. If successful, returns TRUE. |
$tmp_name = $_FILES['file1']['tmp_name']; $path = getcwd() . DIRECTORY_SEPARATOR . 'images'; $name = $path . DIRECTORY_SEPARATOR . $_FILES['file1']['name']; $success = move_uploaded_file($tmp_name, $name); if ($success) { $upload_message = $name . ' has been uploaded.'; }
$_FILES
array contains information about each uploaded file. The index for a file in the $_FILES
array corresponds to the name attribute of the
tag for the file.