Home  >  Article  >  Backend Development  >  PHP file upload method

PHP file upload method

Guanhui
GuanhuiOriginal
2020-05-07 17:48:373702browse

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>

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);

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

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