PHP:图片上传
文章来源:http://www.cnblogs.com/hello-tl/p/7593033.html
<?php
class TL_Update_File{
private $file = null;//接受图片名称
private $files = [];//图片属性
public $size = null;//上传文件大小限制
public $save_path = null;//保存路径
public $mime = null;//文件上传支持类型
private $error = null;//图片不符合要求者
//接受图片
function __construct($file=null){
$this->save_path = str_replace("\\","/",dirname(__FILE__))."/";
$this->file = $file;
if($file){
$this->files = $_FILES[$file];
}else{
$this->files = $_FILES;
}
}
//一系列属性向
private function attribute(){
if($this->file){
$this->empty_ture();
}else{
$this->empty_false();
}
if($this->size){
if($this->file){
$this->Size_ture();
}else{
$this->Size_false();
}
}
if($this->mime){
if($this->file){
$this->mime_ture();
}else{
$this->mime_false();
}
}
}
//判断图片是否为空
function empty_false(){
foreach ($this->files as $key => $value){
if($this->files[$key]['error']){
$this->error[$key] = $value;
$this->error[$key]['tl_error'] = "改图片为空";
unset($this->files[$key]);
}else{
$this->files[$key]['mime'] = substr($value['name'], strrpos($value['name'], ".")+1);
}
}
}
//判断图片是否为空
function empty_ture(){
if($this->files['error']) {
$this->error[$this->file] = $this->files;
$this->error[$this->file]['tl_error'] = "改图片为空";
$this->files=[];
}else{
$this->files['mime'] = substr($this->files['name'], strrpos($this->files['name'], ".") + 1);
}
}
//文件后缀名是否受限制
function mime_ture(){
if($this->files){
if(!in_array($this->files['mime'],$this->mime)){
$this->error[$this->file] = $this->files;
$this->error[$this->file]['tl_error'] = "不支持改后缀名";
$this->files=[];
}
}
}
//文件后缀名是否受限制
function mime_false(){
foreach ($this->files as $key => $value){
if(!in_array($this->files[$key]['mime'],$this->mime)){
$this->error[$key] = $value;
$this->error[$key]['tl_error'] = "不支持改后缀名";
unset($this->files[$key]);
}
}
}
//文件大小是否受限制
function Size_ture(){
if($this->files['size'] > $this->size){
$this->error[$this->file] = $this->files;
$this->error[$this->file] = $this->files;
$this->error[$this->file]['tl_error'] = "文件过大";
$this->files=[];
}
}
//文件大小是否受限制
function Size_false(){
foreach ($this->files as $key => $value){
if($this->files[$key]['size'] > $this->size){
$this->error[$key] = $value;
$this->error[$key]['tl_error'] = "文件过大";
unset($this->files[$key]);
}
}
}
//保存图片
function save_file(){
if($this->files){
$file_path_dir = date('Ym',time()) ."/";
$file_name = time() . rand(00000,99999) . "." . $this->files["mime"];
$this->is_dir_on_off($this->save_path . date('Ym',time()) ."/");
if($this->file){
$this->save_file_ture($file_path_dir,$file_name);
}else{
$this->save_file_false($file_path_dir,$file_name);
}
}
}
//保存图片
function save_file_ture($file_path_dir,$file_name){
move_uploaded_file($this->files["tmp_name"] , $this->save_path . $file_path_dir . $file_name);
}
//保存图片
function save_file_false($file_path_dir,$file_name){
foreach ($this->files as $key => $value){
move_uploaded_file($this->files[$key]["tmp_name"] , $this->save_path . $file_path_dir . $file_name);
}
}
//创建目录
function is_dir_on_off($file_path){
if(!is_dir($file_path)){
mkdir($file_path,0777);
}
}
//保存文件
function move(){
$this->attribute();
$this->save_file();
}
}
文章来源:http://www.cnblogs.com/hello-tl/p/7593033.html
PHP:图片上传的更多相关文章
- Asp.Net Mvc 使用WebUploader 多图片上传
来博客园有一个月了,哈哈.在这里学到了很多东西.今天也来试着分享一下学到的东西.希望能和大家做朋友共同进步. 最近由于项目需要上传多张图片,对于我这只菜鸟来说,以前上传图片都是直接拖得控件啊,而且还是 ...
- 06.LoT.UI 前后台通用框架分解系列之——浮夸的图片上传
LOT.UI分解系列汇总:http://www.cnblogs.com/dunitian/p/4822808.html#lotui LoT.UI开源地址如下:https://github.com/du ...
- JS图片上传预览插件制作(兼容到IE6)
其实,图片预览功能非常地常见.很意外,之前遇到上传图片的时候都不需要预览,也一直没有去实现过.现在手上的项目又需要有图片预览功能,所以就动手做了一个小插件.在此分享一下思路. 一.实现图片预览的一些方 ...
- HTML5笔记:跨域通讯、多线程、本地存储和多图片上传技术
最近做项目在前端我使用了很多新技术,这些技术有bootstrap.angularjs,不过最让我兴奋的还是使用了HTML5的技术,今天我想总结一些HTML5的技术,好记性不如烂笔头,写写文章可以很好的 ...
- 对百度的UEditor多图片上传的一些补充
我已经写了一篇文章关于百度的UEditor提取多图片上传模块.如果还没有看过,请点击以下链接查看 http://www.cnblogs.com/luke1006/p/3719029.html 出差了两 ...
- 使用localResizeIMG3+WebAPI实现手机端图片上传
前言 惯例~惯例~昨天发表的使用OWIN作为WebAPI的宿主..嗯..有很多人问..是不是缺少了什么 - - 好吧,如果你要把OWIN寄宿在其他的地方...代码如下: namespace Conso ...
- TinyMCE的使用(包括汉化及本地图片上传功能)
TinyMCE我就不多介绍了,这是下载地址:https://www.tinymce.com/download/ 下载下来是英文版,要汉化也很简单.首先去网上随便下载个汉化包,然后把汉化包解压后的lan ...
- 包含修改字体,图片上传等功能的文本输入框-Bootstrap
通过jQuery Bootstrap小插件,框任何一个div转换变成一个富文本编辑框,主要特色: 在Mac和window平台下自动针对常用操作绑定热键 可以拖拽插入图片,支持图片上传(也可以获取移动设 ...
- PHP多图片上传实例demo
upload.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ ...
- .NET MVC实现多图片上传并附带参数(ajaxfileupload)
做网站呢,都免不了要做图片上传. 还记得去年做微信的时候用WebAPI+ajaxfileupload.js做了一个能够附带参数上传的功能,博文地址:.NET WebAPI 实现图片上传(包括附带参数上 ...
随机推荐
- bzoj 1927 [Sdoi2010]星际竞速【最小费用最大流】
果然还是不会建图- 设\( i \)到\( j \)有通路,代价为\( w[i][j] \),瞬移到i代价为\( a[i] \),瞬移到i代价为\( a[j] \),逗号前是流量. 因为每个点只能经过 ...
- glance镜像服务
一.glance介绍: 因为云平台是提供Iass层的基础设施服务,我们拿到的是一台虚拟机,那么要用虚拟机的话必须有底层的镜像做支撑,所以说镜像的话也有一个服务来管理.但是我们云平台用的镜像不是装操作系 ...
- react hooks 全面转换攻略(三) 全局存储解决方案
针对 react hooks 的新版本解决方案 一.redux维持原方案 若想要无缝使用原来的 redux,和其配套的中间件 promise,thunk,saga 等等的话 可以使用 redux-re ...
- Luogu P1144 最短路计数 【最短路】 By cellur925
题目传送门 常规的最短路计数问题:注意有重边(重边不用理,看样例),自环(读入时过滤). 另外这个无向图没有权,其实可以直接bfs做,但考虑到以后带权的情况,按spfa走了. 水题被卡了三次(嘤嘤嘤 ...
- nmcli 学习小结
nmcli 是Redhat提供的网络配置编辑工具, 它可直接编辑/etc/sysconfig/network-scripts/ifcfg-xxx , 它是NetworkManager服务的客户端工具, ...
- macbook 快捷键 home ...
home和end是fn+左右,ctrl+home和end是fn+cmd+左右
- 51nod 1186 质数检测 V2
1186 质数检测 V2 基准时间限制:1 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 收藏 关注 给出1个正整数N,检测N是否为质数.如果是,输出"Yes&quo ...
- assets与res/raw资源目录的区别
1.简介 assets和res/raw工程目录下都可以放一些小于1M的文件(2.3版本以前要求,否则将不能读出数据.),这些文件将被原样打包到APK中应用使用. 2.不同 assets目录下的文件将原 ...
- OSW
OSWatcher 工具 下载文档 :Metalink Doc ID 301137.1 Oswatcher 主要用于监控主机资源,如CPU,内存,网络以及私有网络等.其中私有网络需要单独配置. 需要说 ...
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...