当前位置: 首页 > 知识库问答 >
问题:

Codeigniter文件上传许可仅适用于图像,不适用于其他图像

仲承福
2023-03-14

我必须文件上传操作连续,第一个图像像gif|jpg|jpeg|png|svg和第二个psd|rar|zip|doc|word|txt|xlsx|pdf第一个工作正常,我可以上传所有图像,但第二个,我不能上传任何这些类型但当我尝试上传图像在第二段它的作品。

if (isset($_FILES['content_images']['name'])) {
    $count_files = count($_FILES['content_images']['name']);

    for ($i = 0; $i < $count_files; $i++) {
        $_FILES['image']['name'] = $_FILES['content_images']['name'][$i];
        $_FILES['image']['type'] = $_FILES['content_images']['type'][$i];
        $_FILES['image']['tmp_name'] = $_FILES['content_images']['tmp_name'][$i];
        $_FILES['image']['error'] = $_FILES['content_images']['error'][$i];
        $_FILES['image']['size'] = $_FILES['content_images']['size'][$i];
        $config_images['upload_path'] = "./public/site/images/contents";
        $config_images['allowed_types'] = 'gif|jpg|jpeg|png|svg';
        $config_images['max_size'] = 5000;
        $config_images['max_width'] = 7680;
        $config_images['max_height'] = 4320;
        $this->load->library("upload", $config_images);

        if (!$this->upload->do_upload('image')) {
            echo $this->upload->display_errors();
            exit;
        } else {
            $data = $this->upload->data();
            $path_images[] = "public/site/images/contents/".$data['file_name'];
        }
    }
}

if (isset($_FILES['content_files']['name'])) {
    $count_files=count($_FILES['content_files']['name']);

    for ($i = 0; $i < $count_files; $i++) {
        $_FILES['file']['name'] = $_FILES['content_files']['name'][$i];
        $_FILES['file']['type'] = $_FILES['content_files']['type'][$i];
        $_FILES['file']['tmp_name'] = $_FILES['content_files']['tmp_name'][$i];
        $_FILES['file']['error'] = $_FILES['content_files']['error'][$i];
        $_FILES['file']['size'] = $_FILES['content_files']['size'][$i];
        $config_files['upload_path'] = "./public/site/files/contents";
        $config_files['allowed_types'] = 'psd|rar|zip|doc|word|txt|xlsx|pdf';
        $config_files['max_size'] = 5000;
        $config_files['max_width'] = 7680;
        $config_files['max_height'] = 4320;
        $this->load->library("upload",$config_files);

        if (!$this->upload->do_upload('file')) {
            foreach($path_images as $p){
                unlink($p);
            }
            echo $this->upload->display_errors();
            exit;
        } else {
            $data=$this->upload->data();
            $path_files[] = "public/site/files/contents/".$data['file_name'];
        }
    }
}

共有1个答案

柳飞鸾
2023-03-14

我找到了解决方案寻求帮助:你应该只在顶部加载一次库,然后你应该在“如果条件”中初始化它。当您在第一个条件中加载上传库和配置数组时,当您传递到第二个条件时,上传库已经加载并使用第一个条件的配置数组。

$this->load->library("upload");
            if(isset($_FILES['content_images']['name'])){
                $count_files=count($_FILES['content_images']['name']);
                for($i = 0;$i<$count_files;$i++){
                    $_FILES['image']['name'] = $_FILES['content_images']['name'][$i];
                    $_FILES['image']['type'] = $_FILES['content_images']['type'][$i];
                    $_FILES['image']['tmp_name'] = $_FILES['content_images']['tmp_name'][$i];
                    $_FILES['image']['error'] = $_FILES['content_images']['error'][$i];
                    $_FILES['image']['size'] = $_FILES['content_images']['size'][$i];
                    $config_images['upload_path'] = "./public/site/images/contents";
                    $config_images['allowed_types'] = 'gif|jpg|jpeg|png|svg';
                    $config_images['max_size'] = 5000;
                    $config_images['max_width'] = 7680;
                    $config_images['max_height'] = 4320;
                    $this->upload->initialize($config_images);
                    if(!$this->upload->do_upload('image')){
                        echo $this->upload->display_errors();
                        exit;
                    }else{
                        $data=$this->upload->data();
                        $path_images[] = "public/site/images/contents/".$data['file_name'];
                    }
                }
            }
            if(isset($_FILES['content_files']['name'])){
                $count_files=count($_FILES['content_files']['name']);
                for($i = 0;$i<$count_files;$i++){
                    $_FILES['file']['name'] = $_FILES['content_files']['name'][$i];
                    $_FILES['file']['type'] = $_FILES['content_files']['type'][$i];
                    $_FILES['file']['tmp_name'] = $_FILES['content_files']['tmp_name'][$i];
                    $_FILES['file']['error'] = $_FILES['content_files']['error'][$i];
                    $_FILES['file']['size'] = $_FILES['content_files']['size'][$i];
                    $config_files['upload_path'] = "./public/site/files/contents";
                    $config_files['allowed_types'] = 'psd|rar|zip|doc|word|txt|xlsx|pdf';
                    $config_files['max_size'] = 5000;
                    $config_files['max_width'] = 7680;
                    $config_files['max_height'] = 4320;
                    $this->upload->initialize($config_files);
                    if(!$this->upload->do_upload('file')){
                        foreach($path_images as $p){
                            unlink($p);
                        }
                        echo $this->upload->display_errors();
                        exit;
                    }else{
                        $data=$this->upload->data();
                        $path_files[] = "public/site/files/contents/".$data['file_name'];
                    }
                }
            }
 类似资料:
  • 我似乎不能为我的生活得到任何图像懒惰加载插件在wordpress工作。我尝试了懒负载,wp懒负载和bj懒负载。网站上的图像似乎没有一个是“懒惰加载”的。我也使用审计工具(chrome审计)测试了这个。当我删除图像(每页大约有50张图像)时,我的审计绩效和其他分数为99。当我加载图像(使用wordpress循环),我的性能下降到64. 我尝试了每一个延迟加载插件,但它们似乎都不是延迟加载。我正在本地

  • 我正在使用assets文件夹中的hdpi、mdpi、xhdpi,xxhdpi和xxxhdpi来响应本地android。 但是有些图像工作正常,有时即使在提供固定的高度和宽度后,相同的图像也会调整大小(大小增加和减小)。 对于ios来说一切都很好,但是在Android的情况下,图像会失真,有时无法显示。 我已尽一切努力解决此问题,但尚无法解决。

  • 我正在做一个与运行时间有关的练习。exec(),我理解这个运行时。exec不是shell解释器,这就是为什么我执行“bash-c'command'”,但出于某种原因,我可以执行像ls这样的命令,但不能执行echo或重定向或多个命令。这些都不起作用: 这是我的java代码: 我使用以下语法运行上述命令: 这是有效的: 我在Ubuntu 20.04和zsh上使用openjdk 11.0.15。有人能告

  • 我在我的java项目中使用Apache Commons fileupload 1.4库。我有一个带有文件输入和一些隐藏字段的经典表单的html部分。 我在上传周围的文件时遇到问题 它适用于Chrome或Internet Explorer中的10mo文件。但是使用Firefox,我在提交表单后等待几分钟后会超时。 经过一些调试,我看到负责超时的代码是: 原因等待的部分是“解析请求”。 我尝试在Int

  • 我将nginx设置为一种静态文件服务器。出于某种原因,只有当我去123.123.123.123/或123.123.123.123时,它才会起作用。然而,当我去123.123.123.123/static/content/或123.123.123.123/static/content/another.mp3它返回404未找到。下面是位于中并链接到的配置文件。我真的很困惑为什么它不起作用。 如有任何指

  • 问题内容: 完成ajax查询后,我在下面有以下javascript 我所有的图像都有名称=“ pic” 我的目标是在使用此库的周围应用图像边框: http://www.netzgesta.de/instant/ 问题在于,由于某种原因,这可行,但似乎仅适用于其他所有图片,而不是其他所有图片。任何线索为什么上面的代码会跳过其他所有元素? 编辑:我在循环中添加了一个警报,它确实正确地转到0,1,2,3