Home > Backend Development > PHP Problem > PHP file upload method

PHP file upload method

Guanhui
Release: 2023-02-28 22:48:01
Original
3710 people have browsed it

PHP file upload method

How to implement file upload in php

1. Create a form and file type input and set the form attribute "enctype" to "multipart/ form-data";

<form action="./upload_file.php" method="post" enctype="multipart/form-data">
    <input type="file" name="upfile">
    <button type="submit">上传</button>
</form>
Copy after login

2. Save the submitted file through the "move_uploaded_file" function in the PHP program.

$filename = $file_tmp = $_FILES[&#39;upfile&#39;][&#39;name&#39;];
$file_tmp = $_FILES[&#39;upfile&#39;][&#39;tmp_name&#39;];

move_uploaded_file($file_tmp, &#39;Uploads/&#39; . $filename);
Copy after login

The above is the detailed content of PHP file upload method. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template