Home > Article > Backend Development > php file upload function
Only implement a small upload function without paying too much attention to the quality of the code
html
<html> <head><title>test the php</title></head> <body> <h1> upload new file to website</h1> <form action="test3.php" method="post" enctype="multipart/form-data"> <div> <input type="hidden" name="MAX_SIZE" value="100000000"/> <lable for="userfile" >upload a file :</lable> <input type="file" name="userfile" id="userfile" /> <input type="submit" value="submit" /> </div> </form> </body> </html>
<?php if($_FILES['userfile']['error'] > 0) { echo "upload error"."</br>"; exit; } else { echo "upload ok"."</br>"; } if(file_exists("/var/www/".$_FILES['userfile']['name'])) { echo "file already exists"."</br>"; exit; } else { move_uploaded_file($_FILES['userfile']['tmp_name'], "/var/www/".$_FILES['userfile']['name']); //必须修改上传文件名,否则脚本退出会自动删除上传文件 echo "upload finished<br>"; } ?>
Note: Parameter configuration related to upload in the php.ini file
file_uploads, upload_tmp_dir , upload_max_filesize, post_max_size
Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger's permission.
The above introduces the PHP file upload function, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.