PHP新手上路(八)(2) </FORM> </BODY> </HTML> 处理上载文件的PHP文件(receiver.php3) <? function do_upload () { global $uploadfile, $uploadfile_size; global $local_file, $error_msg; if ( $uploadfile == "none" ) { $error_msg = "对不起,你没有选定任何文件上传!"; return; } if ( $uploadfile_size > 2000000 ) { $error_msg = "对不起,你要上传的文件太大了!"; return; } $the_time = time (); // 在这里指定你用来存放上传文件的目录,你需要对以下目录有写权限 // 同时,我们也可以给上传文件指定另外的目录,如:$upload_dir = "/local/uploads"; $upload_dir = "d:/upload"; $local_file = "$upload_dir/$the_time"; if ( file_exists ( '$local_file' ) ) { $seq = 1; while ( file_exists ( "$upload_dir/$the_time$seq" ) ) { $seq++; } $local_file = "$upload_dir/$the_time$seq"; }; rename ( $uploadfile, $local_file ); display_page (); } function display_page () { // 这里是你的页面内容 } ?> <HTML> <HEAD> <TITLE>php3 Receiving Script</TITLE> </HEAD> <BODY> <? if ( $error_msg ) { echo "<B>$error_msg</B><BR><BR>"; } if ( $sendit ) { do_upload (); echo "文件上载成功!"; } elseif ( $cancelit ) { header ( "Location: $some_other_script" ); echo "文件上载失败!"; exit; } else { some_other_func (); } ?> </BODY> </HTML> v