防止选择多个图像,并在Codeigniter的图像上传功能中仅选择单个图像

安吉·苏塔(Ankit Suthar)

我想停止选择多个图像,而只选择单个图像。在此示例中,我在codeigniter中处理图像上载,我可以选择多个图像,但是我只需要选择扔掉的单个图像即可。所以我该如何更改选择以选择单个图像。同样在这个例子中,当我们编辑上传的图像时,旧的图像将被从数据库中删除,我想改变它,但是我不知道在哪里以及如何改变它的代码。

这是我的控制器。

public function index()
{



    $getdata = $this->db->query("SELECT p.id,p.product_description,pd.product_name FROM g_product AS p INNER JOIN g_product_detail AS pd ON p.id = pd.product_id GROUP BY p.id ORDER BY p.id ASC");


    $this->load->view('header');
    $this->load->view('gallery2/index',array('data' => $getdata));



    $this->load->view('footer');


}

public function form()
{
    $this->load->view('gallery2/form', array('error' => ''));
}

public function delete($id)
{
    $getpic = $this->db->query("SELECT full_path FROM g_product_detail WHERE product_id = '{$id}'");
        foreach($getpic->result() as $row)
        {
            unlink($row->full_path);
        }
        $this->db->where('product_id',$id);
        $this->db->delete('g_product_detail');

        $this->db->where('id',$id);
        $this->db->delete('g_product');

        redirect('gallery2/index');
}

private function setup_upload_option()
{
    $config = array();
    $config['upload_path']      = './uploadmulti';
    $config['allowed_types']    = 'jpg|png|gif';
    $config['encrypt_name']     = TRUE;
    $config['overwrite']        = False;
    return $config;
}

public function edit($id)
{
    $getrow = $this->db->query("SELECT * FROM g_product WHERE id= '{$id}' ");
    $row = $getrow->row();


$getdetail = $this->db->query("SELECT * FROM g_product_detail WHERE product_id = '{$id}'");

    $this->load->view('header');
    $this->load->view('gallery2/edit',array('row' => $row,'result' => $getdetail));
    $this->load->view('footer');
}

public function do_update()
{
    $id = $this->input->post('id');
    $data = array(
                    'product_description' => $this->input->post('product_description')


                 );
    $this->db->where('id',$id);
    $te = $this->db->update('g_product',$data);

    if(!empty($_FILES['userfile']['name'][0]))
    {
        $getpic = $this->db->query("SELECT full_path FROM g_product_detail WHERE product_id = '{$id}'");
        foreach($getpic->result() as $row)
        {
            unlink($row->full_path);
        }
        $this->db->where('product_id',$id);
        $this->db->delete('g_product_detail');

        $this->load->library('upload');
    $files = $_FILES;

        $count = count($_FILES['userfile']['name']);
        for($i=0;$i<$count;$i++)
        {
        $_FILES['userfile']['name'] = $files['userfile']['name'][$i];
        $_FILES['userfile']['type'] = $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['size'] = $files['userfile']['size'][$i];
        $_FILES['userfile']['error'] = $files['userfile']['error'][$i];

        $this->upload->initialize($this->setup_upload_option());
        if($this->upload->do_upload() == False)
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('gallery2/form', $error);
        }
        else
        {
            $data = $this->upload->data();
            $dataarray = array(

                'product_id' => $id,
                'product_name' =>$data['file_name'],
                'product_size' =>$data['file_size'],
                'product_ext' =>$data['file_ext'],
                'full_path' =>$data['full_path']
                );
            $this->db->insert('g_product_detail',$dataarray);


        }
    }
    redirect("gallery2/index");
    }
    else
    {
        redirect("gallery2/index");
    }


}


public function do_upload()
{
    $this->load->library('upload');
    $files = $_FILES;

$data = array(
'product_description' => $this->input->post('product_description')
            );
    $ch = $this->db->insert('g_product',$data);
    $id = $this->db->insert_id();
    if($ch > 0)
    {




    $count = count($_FILES['userfile']['name']);
    for($i=0;$i<$count;$i++)
    {
        $_FILES['userfile']['name'] = $files['userfile']['name'][$i];
        $_FILES['userfile']['type'] = $files['userfile']['type'][$i];
        $_FILES['userfile']['tmp_name'] = $files['userfile']['tmp_name'][$i];
        $_FILES['userfile']['size'] = $files['userfile']['size'][$i];
        $_FILES['userfile']['error'] = $files['userfile']['error'][$i];

        $this->upload->initialize($this->setup_upload_option());
        if($this->upload->do_upload() == False)
        {
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('gallery2/form', $error);
        }
        else
        {
            $data = $this->upload->data();
            $dataarray = array(

                'product_id' => $id,
                'product_name' =>$data['file_name'],
                'product_size' =>$data['file_size'],
                'product_ext' =>$data['file_ext'],
                'full_path' =>$data['full_path']
                );
            $this->db->insert('g_product_detail',$dataarray);


        }
    }

    redirect('gallery2/index');
    }

}
须y

我想停止选择多个图像,而只选择单个图像。

这似乎在文件的视图部分中。如果我是正确的,则解决方案将更<input type="file" name="userfile" multiple>改为<input type="file" name="userfile">这应该可以解决您的多张图片选择问题。

简而言之,multiple从文件输入中删除属性(如果使用)。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

从图库中选择多个图像并在recyclerview中显示

来自分类Dev

HTML输入-选择多个图像并在页面中查看它们?

来自分类Dev

将图库中的单个图像选择转换为多个

来自分类Dev

如何使用 Carrierwave (Ruby on Rails) 在 TinyMCE 中实现本地图像上传功能

来自分类Dev

如何从单个输入字段在codeigniter上上传多个图像

来自分类Dev

选择图像表格上传表

来自分类Dev

我希望从iPhone浏览的用户可以选择仅上传视频或图像,而不同时上传视频或图像

来自分类Dev

选择HTML中的图像

来自分类Dev

如何为单个图像提供多个选择选项?

来自分类Dev

取消在引导图像上传器中浏览图像时删除最后选择的图像

来自分类Dev

在单个图像中检测多个图像

来自分类Dev

从图库中选择多个图像

来自分类Dev

在Ionic中选择多个图像

来自分类Dev

跳过reCaptcha多个图像选择

来自分类Dev

从图库中选择图像并在 imageview 中显示

来自分类Dev

Codeigniter:无论用户选择要上传的图像还是不选择的图像,我都尝试提交表单。是否有可能?

来自分类Dev

Codeigniter:无论用户选择要上传的图像还是不选择的图像,我都尝试提交表单。是否可以?

来自分类Dev

如何使用 Codeigniter 中的不同按钮在单个表单中上传多个图像和文本文件?

来自分类Dev

如何使用Codeigniter中的图像处理功能将文本和许多图像与图像合并在一起?

来自分类Dev

使用UIAutomator的Appium Android测试在尝试图像上传功能时显示错误

来自分类Dev

上传前从预览中选择图像

来自分类Dev

文件上传并在angularjs中显示图像

来自分类Dev

Codeigniter 图像未上传

来自分类Dev

SVG中的图像地图选择

来自分类Dev

SVG中的图像地图选择

来自分类Dev

使用 html 中的单个按钮上传图像

来自分类Dev

使用单个输入上传多个图像时,Codeigniter 验证不起作用

来自分类Dev

PHP Image Scraper仅选择图像

来自分类Dev

如何仅选择带有标签的图像

Related 相关文章

  1. 1

    从图库中选择多个图像并在recyclerview中显示

  2. 2

    HTML输入-选择多个图像并在页面中查看它们?

  3. 3

    将图库中的单个图像选择转换为多个

  4. 4

    如何使用 Carrierwave (Ruby on Rails) 在 TinyMCE 中实现本地图像上传功能

  5. 5

    如何从单个输入字段在codeigniter上上传多个图像

  6. 6

    选择图像表格上传表

  7. 7

    我希望从iPhone浏览的用户可以选择仅上传视频或图像,而不同时上传视频或图像

  8. 8

    选择HTML中的图像

  9. 9

    如何为单个图像提供多个选择选项?

  10. 10

    取消在引导图像上传器中浏览图像时删除最后选择的图像

  11. 11

    在单个图像中检测多个图像

  12. 12

    从图库中选择多个图像

  13. 13

    在Ionic中选择多个图像

  14. 14

    跳过reCaptcha多个图像选择

  15. 15

    从图库中选择图像并在 imageview 中显示

  16. 16

    Codeigniter:无论用户选择要上传的图像还是不选择的图像,我都尝试提交表单。是否有可能?

  17. 17

    Codeigniter:无论用户选择要上传的图像还是不选择的图像,我都尝试提交表单。是否可以?

  18. 18

    如何使用 Codeigniter 中的不同按钮在单个表单中上传多个图像和文本文件?

  19. 19

    如何使用Codeigniter中的图像处理功能将文本和许多图像与图像合并在一起?

  20. 20

    使用UIAutomator的Appium Android测试在尝试图像上传功能时显示错误

  21. 21

    上传前从预览中选择图像

  22. 22

    文件上传并在angularjs中显示图像

  23. 23

    Codeigniter 图像未上传

  24. 24

    SVG中的图像地图选择

  25. 25

    SVG中的图像地图选择

  26. 26

    使用 html 中的单个按钮上传图像

  27. 27

    使用单个输入上传多个图像时,Codeigniter 验证不起作用

  28. 28

    PHP Image Scraper仅选择图像

  29. 29

    如何仅选择带有标签的图像

热门标签

归档