php 文件上传实例代码 - php上传下载
来源:自学PHP网
时间:2014-11-28 00:00 作者:
阅读:次
[导读] ?phpif(!$UploadAction):?HTMLHEADTITLE文件上载界面/TITLE/HEADBODYtabletralign=center//开源代码phpfensi.comtdformENCTYPE=multipart/form-dataNAME=SubmitFormACT......
php 文件上传实例代码
- <?php
- 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="提交www.111cn.net" TYPE="submit"></td>
- <td><input NAME="reset" VALUE="重置" TYPE="reset"></td>
- </tr>
- </form>
- </table>
- </center>
- </BODY>
- </HTML>
- <?php
- else:
- ?>
- <HTML>
- <HEAD>
- <TITLE>文件上载代码</TITLE>
- </HEAD>
- <BODY>
-
- <?php
- $UploadAction=0;
- echo "Good!";
- $TimeLimit=60;
- set_time_limit($TimeLimit);
- If(($UploadFile !="none" ))
- {
- $UploadPath=AddSlashes(dirname($PATH_TRANSLATED))."\www.111cn.net\";
- $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>
- <?php
- endif;
- ?>
|