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
Php 是否可以使用GN codeigniter 1.7和循环上传多文件?_Php_Codeigniter_File Upload - Fatal编程技术网

Php 是否可以使用GN codeigniter 1.7和循环上传多文件?

Php 是否可以使用GN codeigniter 1.7和循环上传多文件?,php,codeigniter,file-upload,Php,Codeigniter,File Upload,我一直在尝试使用codeigniter 1.7进行多文件上传。至少我有一些问题要说 我知道这是一个旧版本,但这是我必须处理的 我可以循环$\u文件数组并上传每个文件吗?它似乎不起作用 这是我得到的 $dir_name = $this->input->post('dir'); $file_path = "./system/application/views/courses/course/"; $full_file_path = $file_path

我一直在尝试使用codeigniter 1.7进行多文件上传。至少我有一些问题要说

我知道这是一个旧版本,但这是我必须处理的

我可以循环$\u文件数组并上传每个文件吗?它似乎不起作用

这是我得到的

        $dir_name = $this->input->post('dir');

    $file_path = "./system/application/views/courses/course/";

    $full_file_path = $file_path . $dir_name;


    if (!file_exists($full_file_path)) {
        mkdir($full_file_path, 0777, true);
    }

    $config['upload_path'] = $full_file_path;
    $config['allowed_types'] = 'php|js|html';

    $this->load->library('upload');

    foreach ($_FILES as $files => $fileObject)  //
    {
        if (!empty($fileObject['name']))
        {
            $this->upload->initialize($config);
            if (!$this->upload->do_upload($files))
            {
                $errors = $this->upload->display_errors();
            }
            else
            {
                echo "It worked";
            }
        }
    }
这可能吗


这段代码运行但不上传文件

是,可以循环浏览$\u文件。。。虽然您可能不应该将数组命名为“对象”,但这有点令人困惑

这是我找到的一本用户手册,专门针对1.7中的上传,它看起来与3.0.3非常相似

首先,确保目标文件夹设置为777

您的
config
foreach()和
$this->upload->initialize($config)之外
在内部,您不需要每次都初始化它,因为
$config
项本质上是静态的。但这不太可能解决您的问题

请尝试以下方法:

$config['upload_path'] = $full_file_path;
$config['allowed_types'] = 'php|js|html';

$this->load->library('upload', $config);

foreach (){
   $this->upload->initialize($config); <-- remove this
   ...
}
希望这会有所帮助

$name_array=array(); 
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key => $value)
{
    for ($s = 0; $s < $count; $s++)
    {
$_FILES['userfile']['name'] = $value['name'][$s];
        $_FILES['userfile']['type'] = $value['type'][$s];
        $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
        $_FILES['userfile']['error'] = $value['error'][$s];
        $_FILES['userfile']['size'] = $value['size'][$s];
        $config['upload_path'] = "uploads/item_images/itemimage/original/";
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '8000';
        $config['max_width'] = '10240';
        $config['max_height'] = '7680';
        $this->load->library('upload', $config);
        if ($this->upload->do_upload("image"))
        {
            $data = $this->upload->data();
          if ($this->image_moo->errors)
            {
                print $this->upload->display_errors();
            }
            else
            {
                $name_array[] = $data['file_name'];

            } } } }
$name_array=array();
$count=计数($_文件['userfile']['size']);
foreach($\文件为$key=>$value)
{
对于($s=0;$s<$count;$s++)
{
$\u文件['userfile']['name']=$value['name'][$s];
$\u文件['userfile']['type']=$value['type'][$s];
$\u FILES['userfile']['tmp\u name']=$value['tmp\u name'][$s];
$\u文件['userfile']['error']=$value['error'][$s];
$\u文件['userfile']['size']=$value['size'][$s];
$config['upload_path']=“uploads/item_images/itemmage/original/”;
$config['allowed_types']='gif | jpg | png';
$config['max_size']='8000';
$config['max_width']='10240';
$config['max_height']='7680';
$this->load->library('upload',$config);
如果($this->upload->do_upload(“图像”))
{
$data=$this->upload->data();
如果($this->image\u moo->errors)
{
打印$this->upload->display_errors();
}
其他的
{
$name_数组[]=$data['file_name'];
} } } }

先生/小姐,您是一位传奇人物!这件事已经做了好几天了!!
$name_array=array(); 
$count = count($_FILES['userfile']['size']);
foreach($_FILES as $key => $value)
{
    for ($s = 0; $s < $count; $s++)
    {
$_FILES['userfile']['name'] = $value['name'][$s];
        $_FILES['userfile']['type'] = $value['type'][$s];
        $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$s];
        $_FILES['userfile']['error'] = $value['error'][$s];
        $_FILES['userfile']['size'] = $value['size'][$s];
        $config['upload_path'] = "uploads/item_images/itemimage/original/";
        $config['allowed_types'] = 'gif|jpg|png';
        $config['max_size'] = '8000';
        $config['max_width'] = '10240';
        $config['max_height'] = '7680';
        $this->load->library('upload', $config);
        if ($this->upload->do_upload("image"))
        {
            $data = $this->upload->data();
          if ($this->image_moo->errors)
            {
                print $this->upload->display_errors();
            }
            else
            {
                $name_array[] = $data['file_name'];

            } } } }