The content of this article is about how to upload files to the specified location in PHP (with code). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
test.php (front-end code)
<!DOCTYPE html> <html> <head> <title>文件上传测试</title> <meta charset="utf-8"> </head> <body> <form action="do.php" method="post" enctype="multipart/form-data"> <input type="file" name="img"> <input type="submit" value="上传文件"> </form> </body> </html>
Explanation:
methodmust# under the from tag ##For post
<?php print_r($_FILES); ?>
Array ( [img] => Array ( [name] => 1.jpg [type] => image/jpeg [tmp_name] => C:\Windows\Temp\phpFF07.tmp [error] => 0 [size] => 17164 ) )
<?php print_r($_FILES); $filename=$_FILES['img']['name']; $type=$_FILES['img']['type']; $tmp_name=$_FILES['img']['tmp_name']; $size=$_FILES['img']['size']; $error=$_FILES['img']['error']; //将服务器上的临时文件移动到指定目录下 move_uploaded_file($tmp_name, "img/".$filename);
copy($tmp_name, "img/".$filename);
How to correctly formulate PHP Upload large file settings
# Implement php to upload pictures to the specified location and save the path to the database
The above is the detailed content of How to upload files to a specified location in php (code attached). For more information, please follow other related articles on the PHP Chinese website!