只實現一個小的上傳功能,並沒有過多注意程式碼的品質
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>"; } ?>
, upload_max_filesize, post_max_size
版權聲明:本文為部落客原創文章,未經博主允許不得轉載。以上就介紹了php檔案上傳功能,包含了方面的內容,希望對PHP教學有興趣的朋友有幫助。