【问题标题】:Uploading multiple image with different input file in Codeigniter在 Codeigniter 中上传具有不同输入文件的多个图像
【发布时间】:2015-07-01 18:38:47
【问题描述】:

所以我的表单中有四个输入文件,我将其发送到我的全局 $_FILES 上,并带有以下索引:前、后、右和左。

我想使用 codeigniter 图像类库上传这些。这是我的代码:

public function upload_to_temp($id, $folder, $tags){
            $path = realpath(APPPATH . '../public/resources/temps/' . $folder );
            //makes a directory
            mkdir($path . '/' . $id, 0700);
            //navigate to the newly created path
            $path = realpath(APPPATH . '../public/resources/temps/' . $folder . '/' . $id);

            if(isset($tags)){
                //use these tags to check the files present on submission
                foreach($tags as $tag){
                    if(array_key_exists($tag,$_FILES)){
                        if(!empty($_FILES) && $_FILES[$tag]["name"] != "" && isset($_FILES[$tag]["name"])){
                            $config = array (
                                'source_image' => $_FILES[$tag]["name"],
                                'image_library' => 'gd',
                                'upload_path' => $path, 
                                'file_name' =>  $id . '_' . $tag . '.jpg',
                                'allowed_types' => 'png|jpg|jpeg',
                                'overwrite' => TRUE,
                                'max_size' => '2000',   
                            );
                            $this->_CI->upload->initialize($config);
                            if(!$this->_CI->upload->do_upload()){
                                echo 'Error creating image. ';
                                echo $this->_CI->upload->display_errors();
                            }else{
                                echo 'Success saving to temp folder';
                            }

                            //kapag failed
                            if(!$this->_CI->upload->do_upload()){
                                echo 'Error creating image.';
                                echo $this->_CI->upload->display_errors();
                            }else{
                                //now, the $path will become our resource path for copying and creating thumbnails.
                                $resouce_path = $config['upload_path'] . '/' . $config['file_name'];
                                $this->img_create_thumb($resouce_path, $folder);
                            }

                        }else{
                            //Hindi na dapat marating to!
                            echo $tag . ' not present ';
                        }
                    }else{
                        //use default pictures
                        echo $tag . ' not present ';
                    }

                }
            }

        }

但是它给了我以下错误:

创建图像时出错。

您没有选择要上传的文件。

错误 正在创建图像。

您没有选择要上传的文件。

你做到了 没有选择要上传的文件。

创建图像时出错。

你没有 选择要上传的文件。

创建图像时出错。

您没有选择 要上传的文件。

您没有选择要上传的文件。

对 不存在 离开 不存在

我想我没有正确指定应该上传 $_FILES 上的哪个资源。

我们将不胜感激。

谢谢

【问题讨论】:

    标签: php jquery codeigniter file-upload


    【解决方案1】:

    我通过在 codeigniter 的 do_upload() 中提供索引解决了这个问题

    $this->_CI->upload->do_upload($tag);
    

    【讨论】:

    • 您提出了一个问题来自己回答?如果您查看 CI 文档或搜索您的问题,您会找到很多答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-28
    • 1970-01-01
    • 1970-01-01
    • 2018-02-02
    • 2019-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多