php 无限分类,支持缓存分类树
//这个是后台管理当中的分类列表页
//包含无限分类
include ROOT.'include/tree.class.php';
//声明无限分类
$tree = new tree();
//设置缓存目录
$tree->cDir = ROOT.'cache/class/';
//读入分类缓存
$tree->getCache('class');
//获取缓存
$rootArray = $tree->nodes; //分类信息在写入缓存之前,就已经按照顺序排列好了,不需再次生成分类树,可以拿来直接进行输出
复制代码//只有在修改数据库中的分类表时才需要重新生成分类树
//包含无限分类
include ROOT.'include/tree.class.php';
//声明无限分类
$tree = new tree();
//设置缓存目录
$tree->cDir = ROOT.'cache/class/';
//查询数据库,返回分类的ID,名称,父类3个字段
$db->select('all','class','id,name,parent');
//遍历结果集,并压入无限分类
while ($row = $db->record('all'))
{
$tree->newNode($row['id'],$row['name'],(int)$row['parent']); //父类ID需要为数字
}
//生成分类树,并写入缓存
$tree->putCache('class');
复制代码//另一种更简便的重写缓存方式,该代码是删除分类页中的
//包含无限分类
include ROOT.'include/tree.class.php';
//声明无限分类
$tree = new tree();
//设置缓存目录
$tree->cDir = ROOT.'cache/class/';
//读入分类缓存
$tree->getCache('class');
//是否存在该分类
if (isset($tree->nodes[$id]))
{
//生成查询条件
$condition = 'id='.$id;
//获取该分类的子分类ID
$childsId = $tree->getChildsId($id); //如果存在子分类,改方法返回的是一个一维数组,值分别为各子分类的ID,如果不存在子分类,该方法返回false
//如果存在子分类
if ($childsId)
{
//如果子分类存在,连同子分类一同删除
foreach ($childsId as $childId)
{
$condition .= ' or id='.$childId; //生成删除条件
//卸载无限分类中的条目
unset($tree->nodes[$childId]); //直接将分类树中对应ID的分类信息删除
}
}
//开始删除
$db->delete('class',$condition);
//删除该分类在无限分类中条目
unset($tree->nodes[$id]);
//重写无限分类缓存
$tree->putCache('class');
//输出删除成功标记
exit('OK');
} else {
//不存在则输出错误消息
exit('该分类不存在!');
}
复制代码
php 保存远程服务器图片代码
<?php
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
function SaveHTTPFile($fFileHTTPPath,$fFileSavePath,$fFileSaveName)
{
//记录程序开始的时间
$BeginTime=getmicrotime();
//取得文件名
$fFileSaveName=$fFileSavePath."/".$fFileSaveName;
//取得文件的内容
ob_start();
readfile($fFileHTTPPath);
$img = ob_get_contents();
ob_end_clean();
//$size = strlen($img);
//保存到本地
$fp2=@fopen($fFileSaveName, "a");
fwrite($fp2,$img);
fclose($fp2);
//记录程序运行结束的时间
$EndTime=getmicrotime();
//返回运行时间
return($EndTime-$BeginTime);
}
?>
php经典文件上传类
#*********************************************************
#文件名称:
inc_class.upload.php
#功能描述: 上传文件类
#程序制作:青春一度(adleyliu)
#联系qq
:14339095
2.0.a
#注:转发时请保留此声明信息,这段声明不并会影响你的速度!
#如有修改请将修改后的文件以邮件形式发送给作者一份,谢谢!
#
#*********************************************************
if(!defined('IN_PHPADLEYIU'))
{
exit('Access Denied');
}
/*
//使用说明:
//声明一个上传类
include_once(ADLEYLIU_ROOT.'./inc_class.upload.php');
$_YL_UPLOAD
= array();
$yl_uploadfile = new
yl_upload_class();
$_YL_UPLOAD['yl_filedata'] =
'uploadFile';//表单名
$_YL_UPLOAD['yl_directroy'] =
'upload_files';//上传主目录
$_YL_UPLOAD['file_urldirectroy'] = '/';//
程序路径
$_YL_UPLOAD['yl_settingsnew'] =
''.date('ym').'/'.date('d').'/'.substr(time(), 0,
5).'';//上传子主目录
$_YL_UPLOAD['yl_maxsize'] = 1048576;
//这里以字节为单位(1024*2)*1024=2097152 就是 2M
$_YL_UPLOAD['yl_sizeformat'] =
'k'; //显示文件大小单位b字节,k千,m兆
$_YL_UPLOAD['yl_arrext'] =
array('gif','jpg','jpeg','png','bmp','rar','txt');//允许上传文件类型
$_YL_UPLOAD['yl_ext']
= 0; //0原文件类型上传,1统一为存为jpg
$_YL_UPLOAD['yl_prefix'] =
''.$uid.''.$yl_uploadfile -> yl_createrand(1,0).''.$cid.'';
//在文件名前缀加上特殊字符 //$uid 会员ID $cid 分类ID
$_YL_UPLOAD['yl_suffix'] =
''; //''.$yl_uploadfile -> yl_createrand(3,0).'';
//在文件名后缀加上特殊字符
$_YL_UPLOAD['thumbwidth'] = 100;
//缩略图宽
$_YL_UPLOAD['thumbheight'] = 100;
//缩略图高
$_YL_UPLOAD['maxthumbwidth'] = 500;
//大图高
$_YL_UPLOAD['maxthumbheight'] = 500;
//大图宽
//上传
$yl_uploadfile -> yl_uploadfile();
获取值:
'yl_filename'
=> addslashes($_YL_UPLOAD['yl_filename']),原文件名
'yl_attachment' =>
$_YL_UPLOAD['yl_attachment'],新文件名及路径
'yl_filesize' =>
$_YL_UPLOAD['yl_filesize'] ,文件大小
'yl_filetype' =>
$_YL_UPLOAD['yl_filetype'],文件类型
'yl_isimage' =>
$_YL_UPLOAD['yl_isimage'],是否是图片
'yl_isthumb' =>
$_YL_UPLOAD['yl_isthumb'],是否有小图片
*/
class yl_upload_class
{
function __GET($property_name)
{
if(isset($this -> $property_name))
{
return $this -> $property_name;
} else
{
return
NULL;
}
}
function __SET($property_name,
$value) {
$this -> $property_name =
$value;
}
#*********************************************************
#生成缩略图
#*********************************************************
function makethumb($srcfile) {
global $_YL_UPLOAD;
//判断文件是否存在
if (!file_exists($srcfile))
{
return '';
}
$dstfile =
$srcfile.'.small.jpg';
$bigfile =
$srcfile.'.big.jpg';
//缩略图大小
$tow =
intval($_YL_UPLOAD['thumbwidth']);
$toh =
intval($_YL_UPLOAD['thumbheight']);
if($tow < 60) $tow =
60;
if($toh < 60) $toh = 60;
$make_max = 0;
$maxtow =
intval($_YL_UPLOAD['maxthumbwidth']);
$maxtoh =
intval($_YL_UPLOAD['maxthumbheight']);
if($maxtow >= 300
&& $maxtoh >= 300) {
$make_max =
1;
}
//获取图片信息
$im = '';
if($data =
getimagesize($srcfile)) {
if($data[2] == 1)
{
$make_max =
0;//gif不处理
if(function_exists("imagecreatefromgif"))
{
$im =
imagecreatefromgif($srcfile);
}
}
elseif($data[2] == 2)
{
if(function_exists("imagecreatefromjpeg"))
{
$im =
imagecreatefromjpeg($srcfile);
}
}
elseif($data[2] == 3)
{
if(function_exists("imagecreatefrompng"))
{
$im =
imagecreatefrompng($srcfile);
}
}
}
if(!$im)
return '';
$srcw = imagesx($im);
$srch = imagesy($im);
$towh = $tow/$toh;
$srcwh =
$srcw/$srch;
if($towh <= $srcwh){
$ftow =
$tow;
$ftoh = $ftow*($srch/$srcw);
$fmaxtow = $maxtow;
$fmaxtoh =
$fmaxtow*($srch/$srcw);
} else {
$ftoh =
$toh;
$ftow = $ftoh*($srcw/$srch);
$fmaxtoh = $maxtoh;
$fmaxtow =
$fmaxtoh*($srcw/$srch);
}
if($srcw <= $maxtow
&& $srch <= $maxtoh) {
$make_max =
0;//不处理
}
if($srcw > $tow || $srch > $toh)
{
if(function_exists("imagecreatetruecolor") &&
function_exists("imagecopyresampled") && @$ni =
imagecreatetruecolor($ftow, $ftoh))
{
imagecopyresampled($ni, $im, 0, 0, 0, 0, $ftow,
$ftoh, $srcw,
$srch);
//大图片
if($make_max
&& @$maxni = imagecreatetruecolor($fmaxtow, $fmaxtoh))
{
imagecopyresampled($maxni, $im, 0, 0, 0, 0,
$fmaxtow, $fmaxtoh, $srcw, $srch);
}else if (@$maxni
= imagecreatetruecolor(round($srcw/2),
round($srch/2))){
imagecopyresampled($maxni,
$im, 0, 0, 0, 0, round($srcw/2), round($srch/2), $srcw,
$srch);
}
}
elseif(function_exists("imagecreate") &&
function_exists("imagecopyresized") && @$ni = imagecreate($ftow, $ftoh))
{
imagecopyresized($ni, $im, 0, 0, 0, 0, $ftow,
$ftoh, $srcw,
$srch);
//大图片
if($make_max
&& @$maxni = imagecreate($fmaxtow, $fmaxtoh))
{
imagecopyresized($maxni, $im, 0, 0, 0, 0,
$fmaxtow, $fmaxtoh, $srcw, $srch);
}else if (@$maxni
= imagecreate(round($srcw/2),
round($srch/2))){
imagecopyresized($maxni, $im,
0, 0, 0, 0, round($srcw/2), round($srch/2), $srcw,
$srch);
}
} else
{
return
'';
}
if(function_exists('imagejpeg'))
{
imagejpeg($ni,
$dstfile);
//大图片
if($make_max)
{
imagejpeg($maxni,
$bigfile);
}else{
imagejpeg($maxni,
$bigfile);
}
}
elseif(function_exists('imagepng')) {
imagepng($ni,
$dstfile);
//大图片
if($make_max)
{
imagepng($maxni,
$bigfile);
}else{
imagejpeg($maxni,
$bigfile);
}
}
imagedestroy($ni);
if($make_max)
{
}else{
imagedestroy($maxni);
}
}else{
if(function_exists("imagecreatetruecolor") &&
function_exists("imagecopyresampled") && @$ni =
imagecreatetruecolor($srcw, $srch))
{
imagecopyresampled($ni, $im, 0, 0, 0, 0, $srcw,
$ftoh, $srch,
$srch);
//大图片
$maxni =
imagecreatetruecolor($srch, $srch);
imagecopyresampled($maxni, $im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
} elseif(function_exists("imagecreate")
&& function_exists("imagecopyresized") && @$ni =
imagecreate($ftow, $ftoh)) {
imagecopyresized($ni,
$im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
//大图片
$maxni =
imagecreate($fmaxtow, $fmaxtoh);
imagecopyresized($maxni, $im, 0, 0, 0, 0, $srcw, $srch, $srcw,
$srch);
} else
{
return
'';
}
imagejpeg($ni, $dstfile);
imagejpeg($maxni,
$bigfile);
}
imagedestroy($im);
if(!file_exists($dstfile)) {
return
'';
} else {
return
$dstfile;
}
}
#*********************************************************
#获取随机数函数
#*********************************************************
function
yl_createrand($length, $numeric = 0) {
PHP_VERSION < '4.2.0'
&& mt_srand((double)microtime() * 1000000);
if($numeric)
{
$hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10,
$length) - 1));
} else {
$hash =
'';
$chars =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';///0123456789
$max
= strlen($chars) - 1;
for($i = 0; $i < $length; $i++)
{
$hash .= $chars[mt_rand(0,
$max)];
}
}
return
$hash;
}
#***************
#*********************************************************
#创建目录函数
#*********************************************************
function
createfolder($yl_path)
{
if
(!file_exists($yl_path))
{
$this ->
createfolder(dirname($yl_path));
@mkdir($yl_path,
0777);
}
return $this ->
createfolder;
}
#*********************************************************
#获取文件
名称,大小,类型,临时文件名
#*********************************************************
function
yl_getfilename($yl_type)
{
global
$_YL_UPLOAD;
return
$_FILES[$_YL_UPLOAD['yl_filedata']][$yl_type];
}
#*********************************************************
#获取文件大小
#*********************************************************
function
yl_getfilesize()
{
global
$_YL_UPLOAD;
$yl_filesize = $this ->
yl_getfilename('size');
if($yl_filesize ==
0){
$this ->
alert("请选择上传文件!");
exit;
}
if($yl_filesize
> $_YL_UPLOAD['yl_maxsize']){
switch
(strtolower($_YL_UPLOAD['yl_sizeformat'])){
case
'b':
$yl_maxsizek = $_YL_UPLOAD['yl_maxsize'] .
' B';
break;
case
'k':
$yl_maxsizek =
$_YL_UPLOAD['yl_maxsize']/1024 . '
K';
break;
case
'm':
$yl_maxsizek =
$_YL_UPLOAD['yl_maxsize']/(1024*1024) . '
M';
}
$this ->
alert("上传文件超出限制范围[".$yl_maxsizek."].K!");
exit;
}
return
$yl_filesize;
}
#*********************************************************
#获得文件扩展名
#*********************************************************
function
yl_getfiletype()
{
global
$_YL_UPLOAD;
$pathinfo = pathinfo($this ->
yl_getfilename('name'));
$yl_file_ext =
strtolower($pathinfo['extension']);
//检查扩展名
if(!array_keys($_YL_UPLOAD['yl_arrext'],$yl_file_ext))
{
$this ->
alert("上传文件类型被限制!");
exit;
}
return
$yl_file_ext;
}
#*********************************************************
#上传验证
#*********************************************************
function
yl_upfile($source, $target) {
//
如果一种函数上传失败,还可以用其他函数上传
if (function_exists('move_uploaded_file')
&& @move_uploaded_file($source, $target))
{
@chmod($target, 0666);
return
$target;
} elseif (@copy($source, $target))
{
@chmod($target, 0666);
return
$target;
} elseif (@is_readable($source))
{
if ($fp = @fopen($source,'rb'))
{
@flock($fp,2);
$filedata
=
@fread($fp,@filesize($source));
@fclose($fp);
}
if
($fp = @fopen($target, 'wb')) {
@flock($fp,
2);
@fwrite($fp,
$filedata);
@fclose($fp);
@chmod
($target, 0666);
return
$target;
} else {
return
false;
}
}
}
#*********************************************************
#上传
#*********************************************************
function
yl_uploadfile()
{
global
$_YL_UPLOAD;
$yl_file_path =
$_YL_UPLOAD['yl_directroy'].'/'.$_YL_UPLOAD['yl_settingsnew']
;//建立一个目录
$yl_filename = $this ->
yl_getfilename('name');//原文件名
$yl_filenamenews =
$_YL_UPLOAD['yl_prefix'].''.substr(time(), 5,
9).''.$_YL_UPLOAD['yl_suffix'].'';//重命名
$yl_file_size = $this
-> yl_getfilesize();//获取文件大小
$yl_file_type = $this ->
yl_getfiletype();//获取文件类型
if($_YL_UPLOAD['yl_ext'] ==
0){
$yl_filenamenewsext =
$yl_filenamenews.'.'.$yl_file_type;//改名
}elseif
($_YL_UPLOAD['yl_ext'] == 1){
$yl_filenamenewsext =
$yl_filenamenews.'.jpg';//统一改名为jpg
}
//$yl_tmp_name
= str_replace(' ','',$this ->
yl_getfilename('tmp_name'));//服务器上临时文件名
$yl_tmp_name =
$this ->
yl_getfilename('tmp_name');//服务器上临时文件名
//检查是否已上传
if(<A
href="mailto:!@is_uploaded_file($yl_tmp_name">!@is_uploaded_file
($yl_tmp_name))
{
$this ->
alert("文件已上传!");
exit;
}
//检查目录是否存在,不存在则创建
if(<A
href="mailto:!@is_dir(''.$_YL_UPLOAD
['file_urldirectroy'].''.$yl_file_path.''">!@is_dir(''.$_YL_UPLOAD
['file_urldirectroy'].''.$yl_file_path.''))
{
$this ->
createfolder(''.$_YL_UPLOAD['file_urldirectroy'].''.$yl_file_path.'');//创建
目录
}
//检查目录写权限
if
(<A
href="mailto:!@is_writable(''.$_YL_UPLOAD
['file_urldirectroy'].''.$yl_file_path.''">!@is_writable(''.$_YL_UPLOAD
['file_urldirectroy'].''.$yl_file_path.''))
{
$this ->
alert("上传目录没有写权限!");
exit;
}
$yl_path_name
=
''.$_YL_UPLOAD
['file_urldirectroy'].''.$yl_file_path.'/'.$yl_filenamenewsext.'';
$yl_doupload
= $this -> yl_upfile($yl_tmp_name, $yl_path_name);
if($yl_doUpload ===
false)
{
$this ->
alert("上传失败!");
exit;
}else{
//echo
'上传成功';
//echo
'<br>';
/*
echo
'原文件名:'.$yl_filename.'';
echo
'<br>';
echo
'新文件名及目录:'.$yl_file_path.'/'.$yl_filenamenewsext;
echo
'<br>';
echo
'文件大小:'.$yl_file_size.'';
echo
'<br>';
echo
'文件类型:'.$yl_file_type.'';
*/
$_YL_UPLOAD['yl_filename']
= $yl_filename;
$_YL_UPLOAD['yl_attachment'] =
''.$yl_file_path.'/'.$yl_filenamenewsext.'';
$_YL_UPLOAD['yl_filesize']
= $yl_file_size;
$_YL_UPLOAD['yl_filetype'] =
$yl_file_type;
//检查是否图片
if(@getimagesize($yl_path_name))
{
$_YL_UPLOAD['yl_isimage'] =
1;
///生成缩略图
if ($this
->
makethumb($yl_path_name)){
$_YL_UPLOAD['yl_isthumb']
=
1;
}else{
$_YL_UPLOAD['yl_isthumb']
=
0;
}
}else{
$_YL_UPLOAD['yl_isimage']
= 0;
}
}
return
true;
}
#*********************************************************
#提示
#*********************************************************
function
alert($yl_msg)
{
echo
'<html>';
echo '<head>';
echo
'<title>error</title>';
echo '<meta
http-equiv="content-type" content="text/html;
charset=gb2312">';
echo '</head>';
echo
'<body>';
echo '<script
type="text/javascript">alert("'.$yl_msg.'");history.back();</script>';
echo
'</body>';
echo
'</html>';
exit;
}
}
PHP常用缓存方式入门教程
第一种,把需要缓存的数据进行处理,形成PHP可以直接执行的文件。在需要缓存数据
的时候,通过include方式引入,并使用。
第二种,把需要的数据通过serialize函数序列化后直接保存到文件。在需要使用缓存
数据的时候,通过反序列化读入文件内容并复制给需要的变量,然后使用。
测试结果:
通过测试我们发现,第二种也就是serialize缓存数据的方式更加高效。(数据略去,
最后提供了文章地址下载,大家可以自行测试)
原因分析:
include方式读取缓存的时候,PHP需要执行几个过程
1.读取文件
2.解析所Include的文件
3.执行,给变量赋值
而serialize序列化方式读取缓存的时候:
1.读取数据
2.反序列化数据内容
3.给变量赋值
从以上内容对比的话,可能是由于解析PHP文件内的数组需要的时间超过unserialize反
序列化数组的时间。如果你有兴趣可以查看《PHP filesystem相关函数和include
require的性能效率研究》:http://www.ccvita.com/163.html
测试文件代码:
下载地址:MooPHP-CacheTest.zip
原创地址:http://www.ccvita.com/311.html 有新的研究心得会在这里更新。
CacheTest_IncludeFile.php
CacheTest_SerializeFile.php
总结分析:
第一种,include缓存的方式
优点:增加数据的保密性,和安全性,缓存内容不会被外界发现。
缺点:速度相对较慢。
用途:保存禁止系统外部得知的数据,比如web系统的设置,甚至MySQL信息等的保存
第二种,serialize序列化缓存的方式
优点:速度较快。
缺点:缓存系统文件路径一点曝光,缓存内容会泄露。
用途:缓存最新文章,相关文章等不担心外部得知的数据的时候,可以使用这种方式。
备注:
当装了ea、apc等PHP内存缓存之后,第一种通过include读取缓存的方式速度会高于第
二种serialize序列化缓存的方式。所以在MooPHP框架中,我们对于非敏感信息采用第
二种方式缓存;敏感信息采用第一种方式缓存
php 批量生成缩略图代码
//创建目录(目录, [模式])
function mkdirs($l1, $l2 = 0777){
if(!is_dir($l1)){
//如果目录不存在,递归建立
mkdirs(dirname($l1), $l2);
return @mkdir($l1, $l2);
}
return true;
}
//保存文件(文件, [内容])
function savefile($l1, $l2=''){
if(function_exists(file_put_contents)){
file_put_contents($l1, $l2);
} else{
$fp = @fopen($l1, 'wb');
@fwrite($fp, $l2);
fclose($fp);
}
}
//获取文件后缀(文件)
function getfix($l1){
return end(explode('.', $l1));
}
//是否为允许类型(当前, 允许)
function checkfix($l1, $l2){
if(!is_array($l2)){
$l2 = explode(',', str_replace(' ', '', $l2));
}
return in_array($l1, $l2) ? 1 : 0;
}
class image{
//源地址
var $src;
//新图路径(本地化后)
var $newsrc;
//允许的图类型
var $allowtype = array('.jpg','.gif','.png','.jpeg');
//是否缩略GIF, 为0不处理
var $regif = 0;
//是否保留源文件(1为保留, 0为MD5)
var $keep = 0;
//是否可以覆盖已存在的图片,为0则不可覆盖
var $over = 0;
//图片源目录
var $dir;
//处理后的目录
var $newdir;
function __construct($l1=null, $l2=null){
$this->dir = $l1 ? $l1 : "./images/temp";
$this->newdir = $l2 ? $l2 : "./images/s";
}
function image($l1=null, $l2=null){
$this->__construct($l1, $l2);
}
/**
* 处理后的文件路径
* 将源图片,MD5文件名后保存到新的目录里
*
* @ param rename()
* @ return 处理后的文件名
*/
function reName($src){
//MD5后文件名(例如:3293okoe.gif)
$l1 = substr(md5($src),10,10).strrchr($src,".");
//处理后文件名
$l1 = $this->w.'_'.$this->h.'_'.$l1;
//返回处理后的地址
return $this->newdir.'/'.$l1;
}
/**
* 生成缩略图
*
* @ param Mini(图片地址, 宽度, 高度, 质量)
* 如果要保留原来的文件名,请设置 $o->keep = 1;
* @ return 处理后的图片地址
*/
function Mini($src,$w,$h, $q=80){
$this->src = $src;
$this->w = $w;
$this->h = $h;
//是否处理GIF图
if(strrchr($src, ".") == ".gif" && $this->regif == 0){
return $this->src;
}
//是否保留原文件名,默认不保留
if(!$this->keep){
//改名后的文件地址
$newsrc = $this->reName($src);
} else {
//保持原名
$src = str_replace('\', '/', $src);
$newsrc = $this->newdir.strrchr($src, "/");
}
//如果已存在,直接返回地址
if(file_exists($newsrc) && $this->over == 0){
return $newsrc;
}
//如果是网络文件,先保存
if(strstr($src, "http://") && !strstr($src, $_SERVER['HTTP_HOST'])){
$src = $this->getimg($src);
}
//获取图片属性
$arr = getimagesize($src);
$ow = $arr[0];
$oh = $arr[1];
$ot = $arr[2];
switch($ot){
case 1:
$im = imagecreatefromgif($src);
break;
case 2:
$im = imagecreatefromjpeg($src);
break;
case 3:
$im = imagecreatefrompng($src);
break;
default:
return 0;
}
//处理缩略图
$nim = imagecreatetruecolor($w,$h);
$k1 = round($h/$w,2);
$k2 = round($oh/$ow,2);
if ($k1<$k2){
$oow = $ow;
$ooh = round($ow*$k1);
$sw = 0;
$sh = ($oh-$ooh)/2;
}
else {
$oow = $oh/$k1;
$ooh = $oh;
$sw = ($ow-$oow)/2;
$sh = 0;
}
//生成图片
if(function_exists(imagecopyresampled)){
imagecopyresampled($nim,$im,0,0,$sw,$sh,$w,$h,$oow,$ooh);
}
else {
imagecopyresized($nim,$im,0,0,$sw,$sh,$w,$h,$oow,$ooh);
}
//处理后的目录是否存在
if(!is_dir($this->newdir)){
@mkdir($this->newdir);
}
//保存图片
switch($ot){
case 1:
$rs = imagegif($nim,$newsrc);
break;
case 2:
$rs = imagejpeg($nim,$newsrc,$q);
break;
case 3:
$rs = imagepng($nim,$newsrc);
break;
default:
return 0;
}
//返回处理后路径
return $newsrc;
}
/**
* 保存网络图片
*
* @ param getImg(源图)
* @ return 保存后的本地址址(本地目录的MD5文件名)
*/
function getimg($l1){
$l2 = $this->dir.'/'.substr(md5($l1),10,10).strrchr($l1,".");
//文件存在,直接返回地址
if(file_exists($l2)){
//echo "exits...";
return $l2;
}
//开始获取文件,并返回新路径
$img = file_get_contents($l1);
if($img){
if(!is_dir($this->dir)){
@mkdir($this->dir);
}
savefile($l2, $img);
//echo "file_get..";
return $l2;
}
}
/**
* 转换缩略图(文件名和结构不变)
*
* @ param mini(源地址, 宽度, 高度, 质量 )
* @ return 生成的地址
*/
function reImg($src, $w, $h, $q=80){
$this->keep = 1;
return $this->Mini($src, $w, $h, $q);
}
}
相关文章
- 这篇文章主要介绍了c#自带缓存使用方法,包括获取数据缓存、设置数据缓存、移除指定数据缓存等方法,需要的朋友可以参考下...2020-06-25
- 本文实例讲述了JS+CSS实现分类动态选择及移动功能效果代码。分享给大家供大家参考,具体如下:这是一个类似选项卡功能的选择插件,与普通的TAb区别是加入了动画效果,多用于商品类网站,用作商品分类功能,不过其它网站也可以用,...2015-10-21
- 这篇文章主要介绍了IDEA中的clean,清除项目缓存图文教程,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧...2020-09-25
- 无限级分类在开发中经常使用,例如:部门结构、文章分类。无限级分类的难点在于“输出”和“查询”,例如 将文章分类输出为<ul>列表形式; 查找分类A下面所有分类包含的文章。1.实现原理 几种常见的实现方法,各有利弊。其中...2015-10-23
- 在一些复杂的系统中,要求对信息栏目进行无限级的分类,以增强系统的灵活性。那么PHP是如何实现无限级分类的呢?我们在本文中使用递归算法并结合mysql数据表实现无限级分类。 递归,简单的说就是一段程序代码的重复调用,当把...2015-10-23
- ecshop商品无限级分类代码 function cat_options($spec_cat_id, $arr) { static $cat_options = array(); if (isset($cat_options[$spec_cat_id]))...2016-11-25
- 这篇文章主要介绍了AngularJS实现Model缓存的方式,分享了多种AngularJS实现Model缓存的方法,感兴趣的小伙伴们可以参考一下...2016-02-05
- 这篇文章主要给大家介绍了关于iOS蓝牙设备名称缓存问题的解决方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧...2020-12-08
- 本文给大家一起探讨nodejs下dns的缓存问题,本文给大家介绍的非常详细,感兴趣的朋友一起看看吧...2016-11-22
- 一、数据库设计 -- -- Table structure for table `category` -- CREATE TABLE `category` ( `id` int(11) NOT NULL auto_increment, `catpath` varchar(255) default NULL, `name` varchar(255) default NULL...2015-11-08
- 这篇文章主要介绍了Python深度学习之简单实现猫狗图像分类,文中有非常详细的代码示例,对正在学习python的小伙伴们有非常好的帮助,需要的朋友可以参考下...2021-04-29
- 这篇文章主要介绍了@CacheEvict + redis实现批量删除缓存方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教...2021-10-12
- 这篇文章主要介绍了vue项目中禁用浏览器缓存配置案例,本篇文章通过简要的案例,讲解了该项技术的了解与使用,以下就是详细内容,需要的朋友可以参考下...2021-09-12
- 在本篇文章里小编给大家整理的是一篇关于python删除缓存文件方法,需要的朋友们可以学习下。...2020-07-19
- 这篇文章主要介绍了IIS7、iis7.5中禁止缓存单个静态文件的配置方法,需要的朋友可以参考下...2017-07-06
- 本文介绍了“winform树形菜单无限级分类实例”,需要的朋友可以参考一下...2020-06-25
- 页面不缓存可以让我们有更新就立即更新出来用户不需要清除浏览器缓存或不停的按f5刷新了,这里整理了解一些关于页面不缓存的方法,具体的如下。 一,js,css,图片文件不...2016-09-20
SpringCache 分布式缓存的实现方法(规避redis解锁的问题)
这篇文章主要介绍了SpringCache 分布式缓存的实现方法(规避redis解锁的问题),本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下...2020-11-20- 复制代码 代码如下:<?php//模拟PHP无限分类查询结果return array( array( 'id'=>1, 'pid'=>0, 'name'=>'主页' ), array( 'id'=>2, 'pid'=>0, 'name...2013-10-04
- 小编给大家带来一篇关于安卓手机缓存怎么清理的问题解答,有需要的可以参考一下   安卓手机怎么清理缓存 android清除程序缓存的方法  一,...2017-07-06