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

PHP file upload example tutorial_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:06:51
Original
1084 people have browsed it

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>
Copy after login
<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>
Copy after login
</body>
</html>
Copy after login

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...
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template