Home  >  Article  >  Backend Development  >  PHP file upload example tutorial_PHP tutorial

PHP file upload example tutorial_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:06:511047browse

Okay, let’s take a look at the simplest php file upload tutorial. We will use move_uploaded_file to upload local articles to the server.

Okay, let’s take a look at the simplest php file upload tutorial. Well, we will use move_uploaded_file to upload local articles to the server.

Using PHP, you can upload files to the server.


-------------------------------------------------- -------------------------------

Create a file upload form
Forms for users to upload files can be very helpful.

Take a look at the HTML form below for file upload:

<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

Please note the following HTML form above:

The enctype attribute

tag specifies the content type used when a form is submitted. "Multi/form-data" is used when a form that requires binary data, such as file content, will be uploaded
The type="file" attribute specifies that the input of the tag should be processed as a file. For example, when viewing in a browser, there will be a Browse button next to the input field
NOTE: Allowing users to upload files is a big security risk. Only allow file uploads to trusted users.


Create upload script
The " upload_file.php " file contains the code to upload files:

move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

It’s that simple.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630484.htmlTechArticleOkay let’s take a look at the simplest php file upload example tutorial. We will use move_uploaded_file to upload local files. The article is uploaded to the server. Okay, let's take a look at the simplest php article...
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