<php>上传文件的程序
2016-03-03 21:18
686 查看
<!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> </head> <body> <form action="touxiangchuli.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" /> <input type="submit" value="上传" /> </form> </body> </html>
<!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>touxiangchuli.php</title> </head> <body> <?php /*echo $_FILES["file"]["name"]."<br>";//获取文件名:6.jpg echo $_FILES["file"]["type"]."<br>";//获取文件类型:image/jpeg echo $_FILES["file"]["size"]."<br>";//获取文件大小:6562(字节) echo $_FILES["file"]["tmp_name"]."<br>";//存储在服务器的临时文件名称:D:\wamp\tmp\php653.tmp echo $_FILES["file"]["error"]."<br>";//没有错误,返回:0*/ //1.判断是否出错 if($_FILES["file"]["error"]) { echo "文件上传出错!"; } else { //2.加限制条件 if(($_FILES["file"]["type"]=="image/jpeg" || $_FILES["file"]["type"]=="imge/jpg") && $_FILES["file"]["size"]<=102400)//必须是image/jpeg或者imge/jpg格式的,并且文件小于102400字节 { //3.造一个文件的存储路径 $str = date("YmdHisms",time());//加上时间戳后,可以保证上传的文件名不重复 $filename = "./touxiang/".$str.$_FILES["file"]["name"]; //4.判断文件是否存在 if(file_exists($filename)) { echo "该文件存在!"; } else { //5.移动文件 move_uploaded_file($_FILES["file"]["tmp_name"],iconv("UTF-8","GB2312",$filename)); echo "该文件成功上传,保存在了".$filename; } } else { echo "文件不符合要求"; } } ?> </body> </html>
相关文章推荐
- PHP后台数据处理及与web端进行数据交互
- SFTP 实践
- php批量去除bom的代码
- sublime sublime text3 提示[decode error - output not utf-8]
- PHP功能强大的字符串处理函数
- php中DateTime、diff
- V-Play 文档翻译 ListPage
- (5) PHP 随笔---Smarty模板引擎 使用成熟的Smarty模板 05
- (4) PHP 随笔---Smarty模板引擎MiniSmarty及其优化 03-04
- (3) PHP 随笔---Smarty模板引擎技术基础+MiniSmarty 01-02
- (2) PHP 随笔---跟老韩学(36-38)---PHP基础(变量,基本语法)
- php socket 模型及效率问题
- 深入浅出讲解:php的socket通信
- php cookie 和 cookie跨域访问
- php依赖管理工具Composer的安装和使用
- mac下快速安装gearman和php扩展
- PHP实现登录,注册,密码修改
- BeanPostProcessor使用心得
- php web 信息采集
- 史上最详细的vsftpd配置文件讲解