Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/236.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 上载文件在codeigniter 3中不工作错误:您没有选择任何文件_Php_Codeigniter_View_Controller_Codeigniter 3 - Fatal编程技术网

Php 上载文件在codeigniter 3中不工作错误:您没有选择任何文件

Php 上载文件在codeigniter 3中不工作错误:您没有选择任何文件,php,codeigniter,view,controller,codeigniter-3,Php,Codeigniter,View,Controller,Codeigniter 3,我已经创建了根目录并设置了它的路径,我按原样完成了前端。ide没有给出任何错误,但当我继续时,它说您没有选择任何图像 控制器代码: class Images extends MY_Controller { function __construct() { parent::__construct(); } function index() { $this->data['displayname'] = $this->

我已经创建了根目录并设置了它的路径,我按原样完成了前端。ide没有给出任何错误,但当我继续时,它说您没有选择任何图像

控制器代码:

class Images extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->data['displayname'] = $this->admin->lastname;
        $this->data['images'] = Image::all();
        $this->data['btn'] = 'Save';
        $this->data['content'] = 'admin/images/index';
        $this->load->view('layouts/admin', $this->data);

    }
    public function do_upload() {
        $config['upload_path']   = './uploads/';
        $config['allowed_types'] = '*';
        //$config['max_size']      = 100;
        //$config['max_width']     = 1024;
        //$config['max_height']    = 768;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('images'))
        {
            $error = array('error' => $this->upload->display_errors());
             // echo $this->upload->display_errors();
            $this->load->view('index', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }

    }
}
 public function create($id)
    {
        $config ['upload_path'] = 'uploads';
        $config ['allowed_types'] = 'gif|jpg|png';
        $config ['encrypt_name'] = TRUE;

        $this->upload->initialize($config);
        $package = Package::find($id);

        $files = $_FILES;
        $cpt = count($_FILES ['images'] ['name']);

        for ($i = 0; $i < $cpt; $i++) {

            $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
            $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
            $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
            $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
            $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];
            if ($this->upload->do_upload('images')){
                $upload_data = $this->upload->data();
                $file_name = $upload_data['file_name'];
                $package->create_images(array('image_location' => $file_name));
            }
        }

        redirect('admin/packages/');
    }
}
查看代码:这是用于选择文件的表单

 <?= form_open('admin/images/do_upload') ?>
            <label><?= form_upload('images[]')?></label>
            <div class="input-group-btn">
                <button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
            </div>
        </div>

    </ul>

    <div class="line"></div>

<?= form_submit('', 'Submit', 'class="publish-btn"') ?>

<?= form_close()?>

添加


在文件上传的情况下,您应该使用

<?php form_open_multipart('admin/images/do_upload') ?>

不是这个

<?php  form_open('admin/images/do_upload') ?>

在文件上载情况下,您应该使用

<?php form_open_multipart('admin/images/do_upload') ?>

不是这个

<?php  form_open('admin/images/do_upload') ?>


使用上述代码而不是

<?= form_open('admin/images/do_upload') ?>


使用上述代码而不是

<?= form_open('admin/images/do_upload') ?>

我将多部分添加到我的表单中,这导致了一个无效路径问题,我在添加后通过初始化库解决了这个问题

$this->upload->initialize($config);
在这一行加载库之后

$this->load->library('upload', $config);
首先加载库,然后初始化。 但选择的问题仍然没有解决
我还尝试了一些其他代码。

我将多部分添加到表单中,这造成了一个无效路径的问题,我在添加后通过初始化库解决了这个问题

$this->upload->initialize($config);
在这一行加载库之后

$this->load->library('upload', $config);
首先加载库,然后初始化。 但选择的问题仍然没有解决
我也尝试了一些其他的代码。

经过大量的研究和尝试,我解决了我的问题 这是全部内容 控制器代码:

class Images extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->data['displayname'] = $this->admin->lastname;
        $this->data['images'] = Image::all();
        $this->data['btn'] = 'Save';
        $this->data['content'] = 'admin/images/index';
        $this->load->view('layouts/admin', $this->data);

    }
    public function do_upload() {
        $config['upload_path']   = './uploads/';
        $config['allowed_types'] = '*';
        //$config['max_size']      = 100;
        //$config['max_width']     = 1024;
        //$config['max_height']    = 768;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('images'))
        {
            $error = array('error' => $this->upload->display_errors());
             // echo $this->upload->display_errors();
            $this->load->view('index', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }

    }
}
 public function create($id)
    {
        $config ['upload_path'] = 'uploads';
        $config ['allowed_types'] = 'gif|jpg|png';
        $config ['encrypt_name'] = TRUE;

        $this->upload->initialize($config);
        $package = Package::find($id);

        $files = $_FILES;
        $cpt = count($_FILES ['images'] ['name']);

        for ($i = 0; $i < $cpt; $i++) {

            $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
            $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
            $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
            $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
            $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];
            if ($this->upload->do_upload('images')){
                $upload_data = $this->upload->data();
                $file_name = $upload_data['file_name'];
                $package->create_images(array('image_location' => $file_name));
            }
        }

        redirect('admin/packages/');
    }
}
公共函数创建($id)
{
$config['upload_path']='uploads';
$config['allowed_types']='gif | jpg | png';
$config['encrypt_name']=TRUE;
$this->upload->initialize($config);
$package=package::find($id);
$files=$\u文件;
$cpt=count($_文件['images']['name']);
对于($i=0;$i<$cpt;$i++){
$_FILES['images']['name']=$FILES['images']['name'][$i];
$\u文件['images']['type']=$FILES['images']['type'][$i];
$\u FILES['images']['tmp_name']=$FILES['images']['tmp_name'][$i];
$\u文件['images']['error']=$FILES['images']['error'][$i];
$\u文件['images']['size']=$FILES['images']['size'][$i];
如果($this->upload->do_upload('images')){
$upload_data=$this->upload->data();
$file_name=$upload_data['file_name'];
$package->create_image(数组('image_location'=>$file_name));
}
}
重定向('admin/packages/');
}
}
查看代码:

<div class="container">
    <?= form_open_multipart('admin/images/create/' . $this->uri->segment(4)) ?>
    <div class="row">
        <div class="col-md-8 publish">
            <h4>Image Gallery</h4>
            <div class="line"></div>
            <ul>
                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>



                    <div class="input-group control-group after-add-image">


                        <label><input type="file" name="images[]"></label>

                        <div class="input-group-btn">
                            <button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
                        </div>
                    </div>

                </ul>

                <div class="line"></div>

            <?= form_submit('', 'Submit', 'class="publish-btn"') ?>

            <?= form_close()?>
            <div class="clear-all"></div>
            <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
            <div class="copy-field" style="display: none">
                <div class="control-group input-group" style="margin-top:10px">
                    <label><label><input type="file" name="images[]"></label></label>
                    <div class="input-group-btn">
                        <button class="btn btn-danger delete" type="button"><i class="glyphicon glyphicon-delete"></i> Remove</button>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(document).ready(function() {

                    //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
                    $(".add-image").click(function(){
                        var html = $(".copy-field").html();
                        $(".after-add-image").after(html);
                    });
//here it will remove the current value of the remove button which has been pressed
                    $("body").on("click",".delete",function(){
                        $(this).parents(".control-group").remove();
                    });

                });
            </script>

图像库
    添加

经过大量的研究和尝试大量的代码,我解决了我的问题 这是全部内容 控制器代码:

class Images extends MY_Controller
{
    function __construct()
    {
        parent::__construct();
    }

    function index()
    {
        $this->data['displayname'] = $this->admin->lastname;
        $this->data['images'] = Image::all();
        $this->data['btn'] = 'Save';
        $this->data['content'] = 'admin/images/index';
        $this->load->view('layouts/admin', $this->data);

    }
    public function do_upload() {
        $config['upload_path']   = './uploads/';
        $config['allowed_types'] = '*';
        //$config['max_size']      = 100;
        //$config['max_width']     = 1024;
        //$config['max_height']    = 768;
        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload('images'))
        {
            $error = array('error' => $this->upload->display_errors());
             // echo $this->upload->display_errors();
            $this->load->view('index', $error);
        }
        else
        {
            $data = array('upload_data' => $this->upload->data());

            $this->load->view('upload_success', $data);
        }

    }
}
 public function create($id)
    {
        $config ['upload_path'] = 'uploads';
        $config ['allowed_types'] = 'gif|jpg|png';
        $config ['encrypt_name'] = TRUE;

        $this->upload->initialize($config);
        $package = Package::find($id);

        $files = $_FILES;
        $cpt = count($_FILES ['images'] ['name']);

        for ($i = 0; $i < $cpt; $i++) {

            $_FILES ['images'] ['name'] = $files ['images'] ['name'] [$i];
            $_FILES ['images'] ['type'] = $files ['images'] ['type'] [$i];
            $_FILES ['images'] ['tmp_name'] = $files ['images'] ['tmp_name'] [$i];
            $_FILES ['images'] ['error'] = $files ['images'] ['error'] [$i];
            $_FILES ['images'] ['size'] = $files ['images'] ['size'] [$i];
            if ($this->upload->do_upload('images')){
                $upload_data = $this->upload->data();
                $file_name = $upload_data['file_name'];
                $package->create_images(array('image_location' => $file_name));
            }
        }

        redirect('admin/packages/');
    }
}
公共函数创建($id)
{
$config['upload_path']='uploads';
$config['allowed_types']='gif | jpg | png';
$config['encrypt_name']=TRUE;
$this->upload->initialize($config);
$package=package::find($id);
$files=$\u文件;
$cpt=count($_文件['images']['name']);
对于($i=0;$i<$cpt;$i++){
$_FILES['images']['name']=$FILES['images']['name'][$i];
$\u文件['images']['type']=$FILES['images']['type'][$i];
$\u FILES['images']['tmp_name']=$FILES['images']['tmp_name'][$i];
$\u文件['images']['error']=$FILES['images']['error'][$i];
$\u文件['images']['size']=$FILES['images']['size'][$i];
如果($this->upload->do_upload('images')){
$upload_data=$this->upload->data();
$file_name=$upload_data['file_name'];
$package->create_image(数组('image_location'=>$file_name));
}
}
重定向('admin/packages/');
}
}
查看代码:

<div class="container">
    <?= form_open_multipart('admin/images/create/' . $this->uri->segment(4)) ?>
    <div class="row">
        <div class="col-md-8 publish">
            <h4>Image Gallery</h4>
            <div class="line"></div>
            <ul>
                <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>



                    <div class="input-group control-group after-add-image">


                        <label><input type="file" name="images[]"></label>

                        <div class="input-group-btn">
                            <button class="btn btn-success add-image" type="button"><i class="glyphicon glyphicon-plus"></i> Add</button>
                        </div>
                    </div>

                </ul>

                <div class="line"></div>

            <?= form_submit('', 'Submit', 'class="publish-btn"') ?>

            <?= form_close()?>
            <div class="clear-all"></div>
            <!-- Copy Fields-These are the fields which we get through jquery and then add after the above input,-->
            <div class="copy-field" style="display: none">
                <div class="control-group input-group" style="margin-top:10px">
                    <label><label><input type="file" name="images[]"></label></label>
                    <div class="input-group-btn">
                        <button class="btn btn-danger delete" type="button"><i class="glyphicon glyphicon-delete"></i> Remove</button>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
                $(document).ready(function() {

                    //here first get the contents of the div with name class copy-fields and add it to after "after-add-more" div class.
                    $(".add-image").click(function(){
                        var html = $(".copy-field").html();
                        $(".after-add-image").after(html);
                    });
//here it will remove the current value of the remove button which has been pressed
                    $("body").on("click",".delete",function(){
                        $(this).parents(".control-group").remove();
                    });

                });
            </script>

图像库
    添加

Codeigniter upload library是为一次上载一次而构建的Codeigniter upload library是为一次上载一次而构建的。它不上载图片,因为上载路径似乎无效。上载文件的问题已解决。问题出在视图文件中,而不是控制器中。表单没有响应函数,因为我正在使用:一个文件数组,因为我要提交多个图像。当我使用:一个文件时,它起作用了。但是我需要同时提交多张图片。我应该怎么做才能克服这个问题,因为我已经尝试了数组机制,但它不起作用。添加这一行我这样做了,但它不起作用我正在动态添加输入字段,就像它不是一个抽象的字段数,它可以是3,4或1未上载图片,因为上载路径似乎无效。上载文件的问题已解决。问题出在视图文件中,而不是控制器中。表单没有响应函数,因为我正在使用:一个文件数组,因为我要提交多个图像。当我使用:一个文件时,它起作用了。但是我需要同时提交多张图片。我应该怎么做才能克服这个问题,因为我已经尝试了数组机制,但它不起作用。添加这一行我这样做了,但它不起作用我动态添加输入字段,就像它不是一个抽象的字段数一样,它可以是3、4或1