【问题标题】:Codeigniter multi image upload error messageCodeigniter 多图上传错误信息
【发布时间】:2011-12-03 09:34:11
【问题描述】:

我的多张图片上传有问题。

代码

function tester($yourUniqueId){

             $this->load->library('upload'); 

             for($i=0; $i<count($_FILES); $i++)
             {

               $_FILES['userfile']['name']    = $_FILES['filename']['name'][$i];
               $_FILES['userfile']['type']    = $_FILES['filename']['type'][$i];
               $_FILES['userfile']['tmp_name'] = $_FILES['filename']['tmp_name'][$i];
               $_FILES['userfile']['error']       = $_FILES['filename']['error'][$i];
               $_FILES['userfile']['size']    = $_FILES['filename']['size'][$i];

                $path = './uploads/' . $yourUniqueId;
                mkdir($path);

               $config['file_name']     = "kep_" . $i;
               $config['upload_path']   =  $path;
               $config['allowed_types'] = 'jpg|jpeg|png';
               $config['max_size']      = '0';
               $config['overwrite']     = FALSE;

              $this->upload->initialize($config);

              if($this->upload->do_upload())
              {
                $error += 0;

              }else{
                $error += 1;
                }
             }

                 if($error > 0){ 

                    return FALSE; 
                    }else{
                         return TRUE; 

                     }



}

有点奇怪,因为它返回false,我给它一个回显

if($error > 0){ 
echo 'Something went wrong'; //just for a test                   
return FALSE; 

难道不应该显示回声吗?

我不能让它工作。

代码有什么问题吗?

有人可以给我一个提示吗? 哪里都看不到

【问题讨论】:

    标签: codeigniter image-upload


    【解决方案1】:

    尝试替换这个:

    if($this->upload->do_upload())
    {
        $error += 0;
    }else{
        $error += 1;
    }
    

    有了这个:

    if ( !$this->upload->do_upload())
    {
        $error++;
        echo $this->upload->display_errors();
    }
    

    这应该告诉你出了什么问题。您可能还想包装 mkdir() 函数,以防目录确实存在(我不知道 PHP 如何处理它,否则可能会提前返回):

    if ( !is_dir($path))
    {
        mkdir($path, 0777, TRUE); // make it writable!
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-28
      • 1970-01-01
      • 1970-01-01
      • 2019-02-02
      • 2011-05-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多