php简单文件上传类
- <?php
- header("Content-Type:text/html; charset=utf-8");
- if($_POST['submit']){
- $upfiles = new Upload();
- $upfiles->upload_file();
- }
- class Upload{
- /*作者:mckee 来自:www.phpddt.com*/
- public $upload_name; //上传文件名
- public $upload_tmp_name; //上传临时文件名
- public $upload_final_name; //上传文件的最终文件名
- public $upload_target_dir; //文件被上传到的目标目录
- public $upload_target_path; //文件被上传到的最终路径
- public $upload_filetype ; //上传文件类型
- public $allow_uploadedfile_type; //允许的上传文件类型
- public $upload_file_size; //上传文件的大小
- public $allow_uploaded_maxsize=10000000; //允许上传文件的最大值
- //构造函数
- public function __construct()
- {
- $this->upload_name = $_FILES["file"]["name"]; //取得上传文件名
- $this->upload_filetype = $_FILES["file"]["type"];
- $this->upload_tmp_name = $_FILES["file"]["tmp_name"];
- $this->allow_uploadedfile_type = array('jpeg','jpg','png','gif','bmp','doc','zip','rar','txt','wps');
- $this->upload_file_size = $_FILES["file"]["size"];
- $this->upload_target_dir="./upload";
- }
- //文件上传
- public function upload_file()
- {
- $upload_filetype = $this->getFileExt($this->upload_name);
- if(in_array($upload_filetype,$this->allow_uploadedfile_type))
- {
- if($this->upload_file_size < $this->allow_uploaded_maxsize)
- {
- if(!is_dir($this->upload_target_dir))
- {
- mkdir($this->upload_target_dir);
- chmod($this->upload_target_dir,0777);
- }
- $this->upload_final_name = date("YmdHis").rand(0,100).'.'.$upload_filetype;
- $this->upload_target_path = $this->upload_target_dir."/".$this->upload_final_name;
- if(!move_uploaded_file($this->upload_tmp_name,$this->upload_target_path))
- echo "<font color=red>文件上传失败!</font>";
- }
- else
- {
- echo("<font color=red>文件太大,上传失败!</font>");
- }
- }
- else
- {
- echo("不支持此文件类型,请重新选择");
- }
- }
- /**
- *获取文件扩展名
- *@param String $filename 要获取文件名的文件
- */
- public function getFileExt($filename){
- $info = pathinfo($filename);
- return $info["extension"];
- }
- }
- ?>
- <form enctype="multipart/form-data" method="POST" action="">
- <input type="file" name="file"><input type="submit" name="submit" value="上传">
- </form>
php简单文件上传类的更多相关文章
- ASP.NET 文件上传类 简单好用
调用: UploadFile uf = new UploadFile(); /*可选参数*/ uf.SetIsUseOldFileName(true);//是否使用原始文件名作为新文件的文件名(默认: ...
- PHP 文件上传类
FileUpload.; $]; $_newname = date(,). : To ...
- php 文件上传类 实例分享
最近在研究php上传的内容,找到一个不错的php上传类,分享下. <?php /** * 文件上传类 * class: uploadFile * edit: www.jbxue.com */ c ...
- [上传下载] C#FileUp文件上传类 (转载)
点击下载 FileUp.zip 主要功能如下 .把上传的文件转换为字节数组 .流转化为字节数组 .上传文件根据FileUpload控件上传 .把Byte流上传到指定目录并保存为文件 看下面代码吧 // ...
- ThinkPHP文件上传类
TP框架自带文件上传类使用: 类文件在ThinkPHP/Library/Think/默认在目录下 public function upload(){ $upload = new \Think\Uplo ...
- C#文件上传类,文件流,字节数组等
using System;using System.IO;using System.Web;using System.Web.UI.WebControls; namespace DotNet.Util ...
- Php文件上传类class.upload.php
简介 Class.upload.php是用于管理上传文件的php文件上传类, 它可以帮助你快速的给自己的网站集成上传文件功能.不仅如此,此分类还有一些列的处理功能,可以对上传的文件或者本地的文件进行处 ...
- 自定义MVC框架之工具类-文件上传类
截止目前已经改造了3个类: ubuntu:通过封装验证码类库一步步安装php的gd扩展 自定义MVC框架之工具类-分页类的封装 该文件上传类功能如下: 1,允许定制上传的文件类型,文件mime信息,文 ...
- php 文件上传类,功能相当齐全,留作开发中备用吧。
收藏一个经典好用的php 文件上传类,功能相当齐全,留作开发中备用吧. 好东西,大家都喜欢,才是真的好,哈哈!!! <?php /** * 文件上传类 */ class upload ...
随机推荐
- ASP.NET MVC 过滤器开发与使用
ASP.NET MVC 中给我们提供了内置的过滤器,通过过滤器,我们可以在控制器内的方法前后,添加必须的业务逻辑,如权限验证,身份验证,错误处理等. 今天,我们主要介绍3个过滤器:OutputCach ...
- (转)软件版本中的Alpha,Beta,RC,Trial是什么意思?
版本号:V(Version):即版本,通常用数字表示版本号.(如:EVEREST Ultimate v4.20.1188 Beta )Build:用数字或日期标示版本号的一种方式.(如:VeryCD ...
- makefile --文件文档经链接使用
生成.a 文件是什么? 在makefile的设置使得文件文档可以方便的使用,不用特意的加某些头文件 加入某些产生的链接包
- 7.JAVA_SE复习(文件)
文件和流 1.什么是节点流和处理流 InputStream & OutputStream Reader & Writer 乃节点流, 前面加File之类的名词 的节点流 其余加动词的均 ...
- SMB/CIFS协议解析二
一.拷贝文件(远程-->本地) 1.SMB_COM_NT_CREATE_ANDX (0xa2) 打开文件,获取文件名,获得读取文件的 总长度. 2.SMB_COM_READ ...
- C# SocketHelper 源码
玄机论坛Socket类库源码+Demo 本类库采用C# TcpLister,TcpClient高度封装,采用C# NetworkStream进行异步模式读取数据.采用C# Semaphore来进行并发 ...
- 同时存在两个或多个homestead 虚拟box
开发中发现,不同版本的homestead 里面的环境各不相同,里面的node,npm等版本都不一致,如果需要添加 不同版本的homestead同时存在可以按照以下办法处理. tips: 提供可以离线下 ...
- Shell根据年月日创建文件夹
#!/bin/sh dir_path="/vol/project/log/test/" ..} do #echo "$year" cd $dir_path mk ...
- nodejs npm install全局安装和本地安装的区别
npm的包安装分为本地安装(local).全局安装(global)两种,从敲的命令行来看,差别只是有没有-g而已,比如:代码如下:复制代码npm install # 本地安装npm install - ...
- PHPExcel读取excel03/07版到数组
想总结下PHPExcel的读取excel到数组的function,用的时候直接调取,懒…… 参考了以下链接: http://www.jb51.net/article/29071.htm http:// ...