English 中文(简体)
使用html5 多个属性,在密码用户中上载多个档案
原标题:upload multiple files in Codeigniter using html5 multiple attribute

我的法典如下:

<form action="form-handler.php" method="post" enctype="multipart/form-data">
    <div>
            <input id="myfile" name="myfile" type="file">
            <input value="Upload ►" type="submit">
    </div>
</form>

我想一劳永逸地上载多份档案。 我在控制人员中应当做些什么来上载密码上的选定档案? 我尝试使用密码用户文档上载图书馆,但没有装上多个档案。 但是,在1份档案中,它正在做罚款。

最佳回答

您只能称“Cdigniter s do_upload()”在通过您的系列文件(_FILE发送的每个航道中发挥作用;

这里的代号是控制器功能中接收上载荷的代号:

$this->load->library( upload );
$this->upload->initialize($config); //$config is array like as [in CI s documentation][1] 
$path= uploads/some_folder ; // refers to the root s uploads/some_folder folder
$upload_data = $this->upload->multiFileUpload($path, TRUE);

magic载于multiFileUpload(功能,我从其他人那里获得。 这项职能通过将它列入名为MY_Upload的档案,延伸到CI的上载图书馆。 php in my /application/libraries rafter.

这里是MY_Upload.php的全部内容,它实际上只是、多功能上载()功能,因此,无需恐吓你,而不必知道除了$path外,你想要查阅档案。

<?

class MY_Upload extends CI_Upload {


public function multiFileUpload($path, $protect = FALSE){

  /*
  * Declare uploaded_info and uploaded_files
  * when i m sure $_FILES has some data
  */
 /* if($this->upload_path[strlen($this->upload_path)-1] !=  / )
   $this->upload_path .=  / ;*/

   //$this->upload_path=$path;

  if(isset($_FILES)){

   #Here we check if the path exists if not then create
   /*if(!file_exists($this->upload_path)){
    @mkdir($this->upload_path,0700,TRUE);
   }*/

    if(!file_exists($path)){
    @mkdir($path,0700,TRUE);
   }  
    $uploaded_info  = FALSE;
    /*
    * The structure of $_FILES changes a lot with the array name on the input file,
    * then i m gonna modify $_FILES to make it think the data comes from several
    * input file instead of one "arrayfied" input.
    *
    * The several ways to upload files are controled with this if...else structure
    */
    if(count($_FILES) == 1)
    {
        $main_key = key($_FILES);
        if(is_array($_FILES[$main_key][ name ]))
        {

            foreach($_FILES[$main_key] as $key => $value)
            {                

                for($y = 0; $y < count($value); $y++)
                {

                    $_FILES[$main_key . - . $y][$key] = $value[$y];

                }


            }

            unset($_FILES[$main_key]);

            $uploaded_files  = $_FILES;
        }
        else
        {
            $uploaded_files  = $_FILES;    
        }

    }
    else
    {
        $uploaded_files  = $_FILES;    
    }

   #Here we create the index file in each path s directory
   /*if($protect){
    $folder =   ;
    foreach(explode( / ,$this->upload_path)  as $f){

     $folder .= $f. / ;
     $text = "<?php echo  Directory access is forbidden. ; ?>";

     if(!file_exists($folder. index.php )){
      $index = $folder. index.php ; 
      $Handle = fopen($index,  w );
      fwrite($Handle, trim($text));
      fclose($Handle); 
     }
    }   
   }*/

   #Here we do the upload process

   foreach($uploaded_files as $file => $value){
    if (!$this->do_upload($file))
    {
     $uploaded_info[ error ][]  =  array_merge($this->data(),
              array( error_msg  => $this->display_errors()));

    }
    else
    {
     $uploaded_info[ upload_data ][] =  array_merge($this->data(),
              array( error_msg  => $this->display_errors()));
    }
   }  
  }

  #Then return what happened with the files
  return $uploaded_info;
 } 
}
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签