if(!$uploadaction): ?> <html> <head> <title>檔案上傳介面</title> </head> <body> <table> <tr align="center"> <td><form enctype="multipart/form-data" name="submitform" action="upload.php" method="post"> <input type="hidden" name="max_file_size" value="1000000"><input type="hidden" name="uploadaction" value="1"> </td></tr> <tr align="center"> <td><input name="uploadfile" type="file" size="30"></td> </tr> <tr align="center"> <td><input name="submit" value="提交" type="submit"></td> <td><input name="reset" value="重設" type="reset"></td> </tr> </form> </table> </center> </body> </html> <? else: ?> <html> <head> <title>檔案上傳代碼</title> </head> <body> <? $uploadaction=0; echo "good!"; $timelimit=60; /*設定逾時限制時間 預設時間為30秒 設定為0時為不限時 */ set_time_limit($timelimit); if(($uploadfile !="none" )) { $uploadpath=addslashes(dirname($path_translated))."\upload\"; //上傳檔案存放路徑 $filename=$uploadpath.$uploadfile_name; //上傳檔案名稱 if($uploadfile_size < 1024) //上傳檔案大小 { $filesize=(string)$uploadfile_size." 位元組"; } elseif ($uploadfile_size <(1024 * 1024)) { $filesize=number_format((double)($uploadfile_size/1024), 1) . " kb"; } else{ $filesize=number_format((double)($uploadfile_size / (1024 * 1024)), 1) . " mb"; } if(!file_exists($filename)) { if(copy($uploadfile,$filename)) { echo "檔案 $uploadfile_name ($filesize)上傳成功!"; } else { echo "檔案 $uploadfile_name上傳失敗!"; } unlink($uploadfile); } else { echo "檔案 $uploadfile_name已經存在!"; } } else { echo "你沒有選擇任何檔案上傳!"; } set_time_limit(30); //恢複預設逾時設定 ?> <br><a href = "upload.php">返回</a> </body> </html> <? endif; ?> 方法二 <html> <head> <title>檔案上傳</title> </head> <body> <table> <form enctype="multipart/form-data" name=myform method="post"> <tr><td>檔案上傳</td><td><input name="myfile" type="file"></td></tr> <tr><td colspan="2"><input name="submit" value="上傳" type="submit"> </form> <?php if(isset($submit)){ if($myfile != "none") { $upload_dir = "c:winnt emp"; $up=copy($myfile,$upload_dir); if($up==1) { print("檔案上傳成功!"); } else { print ("檔案上傳失敗."); } unlink ($myfile); } else { print("你沒有上傳任何檔案"); } } ?> </td></tr> </table> </body> </html> |