Home >Backend Development >PHP Tutorial >About a file upload code for PHP beginners (1/3)_PHP tutorial

About a file upload code for PHP beginners (1/3)_PHP tutorial

WBOY
WBOYOriginal
2016-07-20 11:09:23906browse

Create a file upload form
It is very useful to allow users to upload files from a form.

Create a file upload form
It is very useful to allow users to upload files from the form.
Please look at the html form below for uploading files:
Copy the code as follows:



enctype="multipart/form-data">







Please note the following information about this form:

The enctype attribute of the tag Which content type to use when submitting the form. Use "multipart/form-data" when your form requires binary data, such as file content. The type="file" attribute of the
tag specifies that the input should be processed as a file. For example, when previewing in a browser, you'll see a browse button next to the input box.
Note: Allowing users to upload files is a huge security risk. Please allow only trusted users to perform file upload operations.
Create an upload script
"upload_file.php" file contains the code for uploading files:
Copy the code as follows:

if ($_files["file "]["error"] > 0)
{
echo "error: " . $_files["file"]["error"] . "
";
}
else
{
echo "upload: " . $_files["file"]["name"] . "
";
echo "type: " . $_files ["file"]["type"] . "
";
echo "size: " . ($_files["file"]["size"] / 1024) . " kb
";
echo "stored in: " . $_files["file"]["tmp_name"];
}
?>

1 2 3

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/444814.htmlTechArticleIt is very useful to create a file upload form to allow users to upload files from the form. Creating a File Upload Form It is very useful to allow users to upload files from a form. Please see below...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn