PHP上传文件实现
来源:互联网 发布:樱桃3000和3494 mac 编辑:程序博客网 时间:2024/05/16 08:08
实现代码见下。
upload.html
<html><head> <title>上载文件表单</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body> <form method="post" action="upload.php" enctype="multipart/form-data"> <table border=0 cellspacing=0 cellpadding=0 align=center width="100%"> <tr> <td width=55 height=20 align="center"><input type="hidden" name="MAX_FILE_SIZE" value="200000000">文件: </TD> <td height="16"> <input name="file" type="file" value="浏览"/> <input type="submit" value="上传" name="B1"/> </td> </tr> </table> </form></body></html>
upload.php
<html> <head> <title>上传结果</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head><body><?php $uploaddir = "./files/";//设置文件保存目录 注意包含/ $type=array("jpg","gif","bmp","jpeg","png");//设置允许上传文件的类型 //获取文件后缀名函数 function fileext($filename) { return substr(strrchr($filename, '.'), 1); } //生成随机文件名函数 function random($length) { $hash = 'CR-'; $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'; $max = strlen($chars) - 1; mt_srand((double)microtime() * 1000000); for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; }$a=strtolower(fileext($_FILES['file']['name'])); //判断文件类型 if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type)) { $text=implode(",",$type); echo "您只能上传以下类型文件: ",$text,"<br>"; } //生成目标文件的文件名 else{ $filename=explode(".",$_FILES['file']['name']); do { $filename[0]=random(10); //设置随机数长度 $name=implode(".",$filename); //$name1=$name.".Mcncc"; $uploadfile=$uploaddir.$name; } while(file_exists($uploadfile)); if (move_uploaded_file($_FILES['file']['tmp_name'],$uploadfile)) {//输出图片预览 echo "<center>您的文件已经上传完毕 上传图片预览: </center>";echo "<br><center><a href='javascript:history.go(-1)'>继续上传</a></center>";echo "<br><center><img src='$uploadfile'></center>"; } else {echo "upload error:".$_FILES['file']['error']; }} ?></body></html>
- PHP实现文件上传
- 实现php文件上传
- PHP上传文件实现
- php实现文件上传
- [php] 实现文件上传
- PHP实现文件上传
- php实现文件上传
- PHP实现文件上传
- PHP-实现文件上传
- PHP 实现文件上传
- php实现文件上传
- PHP实现文件上传例子
- SIMPLE PHP -- 实现文件上传
- 用PHP实现文件上传
- PHP实现文件上传例子
- 用PHP实现文件上传
- FLASH+PHP实现文件上传
- php如何实现文件上传 ?
- UINavigationController使用详解
- Balsamiq Mockups
- linux 并发服务器
- MPEG压缩标准
- shell脚本中一些特殊符号
- PHP上传文件实现
- json
- HDU 动态规划(46道题目)倾情奉献~ 【只提供思路与状态转移方程】
- ORACLE流复制(全库级复制)
- 软件架构设计之Utility模块——内存分配
- Eclipse快捷键大全
- 利用UpdatePanel无刷新 更新数据绑定控件
- html5 canvas
- 傅里叶变换的应用