codeigniter教程之多文件上传使用示例


<?php if(!defined("BASEPATH")){ exit("No direct script access allowed"); }

/**
  * Multi-Upload
  *
  * Extends CodeIgniters native Upload class to add support for multiple
  * uploads.
  *
  * @package  CodeIgniter
  * @subpackage Libraries
  * @category Uploads
  */
  class MY_Upload extends CI_Upload {


   /**
    * Properties
    */
     protected $_multi_upload_data   = array();
    protected $_multi_file_name_override = "";


   /**
    * Initialize preferences
    *
    * @access public
    * @param array
    * @return void
    */
    public function initialize($config = array()){
     //Upload default settings.
     $defaults = array(
         "max_size"   => 0,
         "max_width"   => 0,
         "max_height"  => 0,
         "max_filename"  => 0,
         "allowed_types"  => "",
         "file_temp"   => "",
         "file_name"   => "",
         "orig_name"   => "",
         "file_type"   => "",
         "file_size"   => "",
         "file_ext"   => "",
         "upload_path"  => "",
         "overwrite"   => FALSE,
         "encrypt_name"  => FALSE,
         "is_image"   => FALSE,
         "image_width"  => "",
         "image_height"  => "",
         "image_type"  => "",
         "image_size_str" => "",
         "error_msg"   => array(),
         "mimes"    => array(),
         "remove_spaces"  => TRUE,
         "xss_clean"   => FALSE,
         "temp_prefix"  => "temp_file_",
         "client_name"  => ""
        );

//Set each configuration.
     foreach($defaults as $key => $val){
      if(isset($config[$key])){
       $method = "set_{$key}";
       if(method_exists($this, $method)){
        $this->$method($config[$key]);
       } else {
        $this->$key = $config[$key];
       }
      } else {
       $this->$key = $val;
      }
     }

//Check if file_name was provided.
     if(!empty($this->file_name)){
      //Multiple file upload.
      if(is_array($this->file_name)){
       //Clear file name override.
       $this->_file_name_override = "";

//Set multiple file name override.
       $this->_multi_file_name_override = $this->file_name;
      //Single file upload.
      } else {
       //Set file name override.
       $this->_file_name_override = $this->file_name;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/0370ffe02d07c62981c73c071ae8bee3.html