move_uploaded_file()函數將上傳文件存儲到指定位置。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>單文件上傳</title> <body> <?php if(!empty($_FILES['up_file']['name'])){ $fileinfo = $_FILES['up_file']; if($fileinfo['size'] < 1000000 && $fileinfo['size'] > 0){ move_uploaded_file($fileinfo['tmp_name'],$fileinfo['name']); echo '上傳成功'; }else{ echo '文件太大或未知'; } } ?> <form action="" method="post" enctype="multipart/form-data" name="form"> <input name="up_file" type="file"/> <input name="submit" type="submit" value="上傳"/> </form> </body> </html>