php文件上传类
<?php
header("Content-Type:text/html; charset=utf-8");
if($_POST['submit']){
$upfiles = new Upload();
$upfiles->upload_file();
}
class Upload{
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=; //允许上传文件的最大值
//构造函数
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,);
}
$this->upload_final_name = date("YmdHis").rand(,).'.'.$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 ...
- PHP实现的多文件上传类及用法示例
这篇文章主要介绍了PHP实现的多文件上传类及用法,详细分析了php实现的多文件上传类与具体的使用技巧,需要的朋友可以参考下 1.upFiles.css.php 文件 <?php class Up ...
随机推荐
- hoj3152-Dice 等比数列求和取模
http://acm.hit.edu.cn/hoj/problem/view?id=3152 Dice My Tags (Edit) Source : Time limit : sec Memory ...
- 调用gluNurbsCurve绘制圆弧
<OpenGL编程指南>第12章第3小结专门介绍调用GLU绘制NURBS曲线或曲面,很可惜的是并未给出绘制圆弧的例子.网上可以找到很多绘制整个园的例子,却没圆弧例子,自己瞎折腾了2个礼拜, ...
- Integer Inquiry
Integer Inquiry Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Sub ...
- Tenth scrum meeting - 2015/11/4
我们的项目开发已经渐渐进入了后期,每个模块都只剩下了一小块任务待做,同学们在做自己的模块的同时也开始对各个同学的模块进行合并. 其中最麻烦的就是视频播放模块与其他模块的合并了,由于该模块的实现需要添加 ...
- java笔记--查看和修改线程的优先级
查看和修改线程的优先级 java中每一个线程都有优先级属性,在默认情况下,新建的线程的优先级与创建该线程的线程优先级相同.每当线程调度器选择要运行的线程时,通常选择优先级较高的线程. 注:线程的优先级 ...
- 安装 openSUSE Leap 42.1 之后要做的 8 件事
导读 openSUSE Leap 确实是个巨大的飞跃,它允许用户运行一个和 SUSE Linux 企业版拥有同样基因的发行版.和其它系统一样,为了实现最佳的使用效果,在使用它之前需要做些优化设置. 下 ...
- Apache Common DbUtils
前段时间使用了Apache Common DbUtils这个工具,在此留个印,以备不时查看.大家都知道现在市面上的数据库访问层的框架很多,当然很多都是包含了OR-Mapping工作步骤的 例如大家常用 ...
- HTML前端
1.<html>内容</html> 解释:HTML文档的文档标记,也成为HTML开始标记 功能:这对标记分别位于网页的最前端和最后端 <html>在最前段表示网页的 ...
- mysql中limit与in不能同时使用的解决方式.
mysql中limit与in不能同时使用的解决方式. 分类: MySQL2011-10-31 13:53 1277人阅读 评论(0) 收藏 举报 mysqlsubquery MySQL5.1中子查询是 ...
- android文章学习 侧滑菜单实现
http://blog.csdn.net/jj120522/article/details/8075249 http://blog.csdn.net/lilybaobei/article/detail ...