This article mainly introduces the CI framework to implement the function of recursively generating file paths and regenerating images, involving the CodeIgniter framework custom image controller class to implement file directory recursion and calling the image processing extension class to perform image generation related operation skills, which are required Friends can refer to
The example in this article describes the CI framework's ability to recursively generate file paths and regenerate images. Share it with everyone for your reference, the details are as follows:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); set_time_limit(0); class Img_build extends CI_Controller{ private static $img_path = 'upload_old/'; private static $new_path = 'upload/'; function __construct() { parent::__construct(); } /** * 获取需要读取的路径的信息 * $map = array ( * '路径名' => array (文件1, 文件2, 文件3) * ) */ public function index() { $this->load->helper('directory'); //读取路径的信息 $map = directory_map(self::$img_path, FALSE, TRUE); echo "<pre class="brush:php;toolbar:false">"; print_r($map); echo ""; if(!empty($map) && is_array($map)) { $this->build_path($map); } } /** * 递归生成相应的路径 * @param array $map */ private function build_path($map = array()) { if(!file_exists(self::$new_path)) { mkdir(self::$new_path, 0777); } foreach($map as $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."
"; // 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."
The above is the entire content of this article, I hope it will be helpful to everyone’s study , please pay attention to the PHP Chinese website for more related content!
Related recommendations:
How to use the CI framework to optimize file uploads and upload multiple files
About CI Framework Unlimited Implementation of level classification and recursion
The above is the detailed content of Introduction to the function of CI framework to recursively generate file paths and regenerate images. For more information, please follow other related articles on the PHP Chinese website!