CI框架实现递归生成文件路径并重新生成图片功能
本文实例讲述了CI框架实现递归生成文件路径并重新生成图片功能。分享给大家供大家参考,具体如下:
array(文件1,文件2,文件3)
*)
*/
publicfunctionindex()
{
$this->load->helper('directory');
//读取路径的信息
$map=directory_map(self::$img_path,FALSE,TRUE);
echo"";
print_r($map);
echo"
";
if(!empty($map)&&is_array($map))
{
$this->build_path($map);
}
}
/**
*递归生成相应的路径
*@paramarray$map
*/
privatefunctionbuild_path($map=array())
{
if(!file_exists(self::$new_path))
{
mkdir(self::$new_path,0777);
}
foreach($mapas$key=>$val)
{
$old_img_path=self::$img_path;
$old_tmp_path=self::$img_path.$key.'/';
$new_img_path=self::$new_path;
$new_tmp_path=self::$new_path.$key.'/';
if(is_dir($old_tmp_path))
{
//echo$new_tmp_path;
if(!file_exists($new_tmp_path))
{
mkdir($new_tmp_path,0777);
}
self::$img_path=$old_tmp_path;
self::$new_path=$new_tmp_path;
echo'path:'.self::$img_path."
";
$this->load->helper('directory');
$c_map=directory_map($old_tmp_path,FALSE,TRUE);
//echo"";
//print_r($c_map);
//echo"
";
if(!empty($c_map)&&is_array($c_map))
{
$this->build_path($c_map);
}
}
if(is_file(self::$img_path.$val))
{
echo'file:'.self::$img_path.$val."
";
$img=array();
$img['source_image']=self::$img_path.$val;
$img['new_image']=self::$new_path.$val;
$this->build_img($img);
}
self::$img_path=$old_img_path;
self::$new_path=$new_img_path;
}
}
/**
*根据原图片生成新的图片
*@paramarray$img
*$img=array('source_image'=>'原图片的路径','new_image'=>'新图片路径')
*/
privatefunctionbuild_img($img=array())
{
if(!is_array($img)||empty($img))
{
returnFALSE;
}
//设置图像生成参数
$config['image_library']='gd2';//设置图像库
$config['source_image']=$img['source_image'];//设置原始图像的名字/路径
$config['create_thumb']=FALSE;//让图像处理函数产生一个预览图像
$config['maintain_ratio']=TRUE;//指定是否在缩放或使用硬值的时候使图像保持原始的纵横比例
//$config['quality']=200;
$img_info=array();
$img_info=getimagesize($config['source_image']);//获取图片的尺寸
if(is_array($img_info)&&!empty($img_info))
{
$config['width']=$img_info[0];
$config['height']=$img_info[1];
}
$config['new_image']=$img['new_image'];//新图片路径
$this->load->library('image_lib',$config);//加载图片处理类
$this->image_lib->initialize($config);//调用
if(!$this->image_lib->resize())
{
echo$this->image_lib->display_errors();
}
$this->image_lib->clear();//清除图片处理参数
}
}
?>
更多关于CodeIgniter相关内容感兴趣的读者可查看本站专题:《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《php优秀开发框架总结》、《ThinkPHP入门教程》、《ThinkPHP常用方法总结》、《ZendFrameWork框架入门教程》、《php面向对象程序设计入门教程》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家基于CodeIgniter框架的PHP程序设计有所帮助。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。