Home >Backend Development >PHP Tutorial >Detailed explanation of file upload in PHP (with code examples)
PHP
In actual combat, users often need to upload files to the server for storage. This article will take you to see how to upload files to the server. middle.
1.HTML file
<html> <body> <form action="service_file.php" method="post" enctype="multipart/form-data"> <label for="file">待上传文件名:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="提交" /> </form> </body> </html>
##2.service_file.php
<?php echo "<pre class="brush:php;toolbar:false">"; print_r($_FILES['file']); $uploaddir = './upload/';//存放的路径 $uploadfile = $uploaddir . basename($_FILES['file']['name']); if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) { echo "文件上传成功"; } else { echo "文件上传失败"; }
Recommended: 《2021 PHP interview questions summary (collection)》《php video tutorial》
The above is the detailed content of Detailed explanation of file upload in PHP (with code examples). For more information, please follow other related articles on the PHP Chinese website!