Codeigniter多图上传错误信息

发布于 2024-12-19 03:19:24 字数 1625 浏览 3 评论 0原文

我的多图像上传有问题。

代码

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; 

难道它不应该显示回声吗?

我无法让它发挥作用。

代码有什么问题吗?

有人可以给我提示吗? 我在任何地方都看不到它

I have a problem with my multi image upload.

The code

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; 

                     }



}

Its a bit strange, because, it it returns false, and i give it an echo

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

Doesnt it sopose to show the echo?

I cant make it work.

Is there something worng with the code?

Could please someone give me a hint?
I cant see it anywhere

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡水深流 2024-12-26 03:19:24

尝试替换这个:

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!
}

Try replacing this:

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

With this:

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

That should tell you what went wrong. You also might want to wrap the mkdir() function just in case the directory does exist (I don't know how PHP handles it otherwise--might be returning early):

if ( !is_dir($path))
{
    mkdir($path, 0777, TRUE); // make it writable!
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文