Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.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多文件上载返回false_Php_Codeigniter_File Upload - Fatal编程技术网

Php CodeIgniter多文件上载返回false

Php CodeIgniter多文件上载返回false,php,codeigniter,file-upload,Php,Codeigniter,File Upload,我想在成功将一些数据插入数据库后上载文件,但文件上载不起作用 以下是我上传文件的代码,但它没有上传 控制器 public function saveReceipt(){ $doc=$this->receipt_m->saveReceipt_m(); if($doc){ $countfiles = count($_FILES['attatchments']['name']); for($i=0;$i<$countfiles;$i++){

我想在成功将一些数据插入数据库后上载文件,但
文件上载
不起作用

以下是我上传文件的代码,但它没有上传

控制器

public function saveReceipt(){
    $doc=$this->receipt_m->saveReceipt_m();
    if($doc){
      $countfiles = count($_FILES['attatchments']['name']);

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

        if(!empty($_FILES['attatchments']['name'][$i])){

          // Define new $_FILES array - $_FILES['file']
          $_FILES['file']['name'] = $_FILES['attatchments']['name'][$i];
          $_FILES['file']['type'] = $_FILES['attatchments']['type'][$i];
          $_FILES['file']['tmp_name'] = $_FILES['attatchments']['tmp_name'][$i];
          $_FILES['file']['error'] = $_FILES['attatchments']['error'][$i];
          $_FILES['file']['size'] = $_FILES['attatchments']['size'][$i];

          // Set preference
          $config['upload_path'] = base_url("assets/attachments"); 
          $config['allowed_types'] = 'pdf|txt';
          $config['max_size'] = '5000'; // max_size in kb
          $config['file_name'] = $_FILES['attatchments']['name'][$i];

          //Load upload library
          $this->load->library('upload',$config); 
          $arr = array('msg' => 'something went wrong', 'success' => false);
          // File upload
          if($this->upload->do_upload('file')){

           $data = $this->upload->data(); 
           $arr = array('msg' => 'Image has been uploaded successfully', 'success' => true);

          }
        }

      }
      echo json_encode($arr);
    }else{
      $response=array("status"=>false);
    }
   }
公共函数saveReceipt(){
$doc=$this->receipt\u m->saveReceipt\u m();
如果($doc){
$countfiles=count($_文件['attachments']['name']);
对于($i=0;$iload->library('upload',$config));
$arr=array('msg'=>'出错','success'=>错误);
//文件上传
如果($this->upload->do_upload('file')){
$data=$this->upload->data();
$arr=array('msg'=>'图像已成功上载,'success'=>true);
}
}
}
echo json_编码($arr);
}否则{
$response=array(“状态”=>false);
}
}
查看

<form class="horizontal-form" name="frmSaveReceipt" id="frmSaveReceipt"  enctype="multipart/form-data"> 
     <input type="file" name="attatchments[]" id="file" multiple="multiple">
   </form 


下面的代码为我工作,请尝试这个 控制器代码如下

$info=$this->input->post();
$data = array();
  // If file upload form submitted

$countfiles = count($_FILES['galleryImage']['name']);

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

if(!empty($_FILES['galleryImage']['name'][$i])){

      // Define new $_FILES array - $_FILES['file']
  $_FILES['file']['name'] = $_FILES['galleryImage']['name'][$i];
  $_FILES['file']['type'] = $_FILES['galleryImage']['type'][$i];
  $_FILES['file']['tmp_name'] = $_FILES['galleryImage']['tmp_name'][$i];
  $_FILES['file']['error'] = $_FILES['galleryImage']['error'][$i];
  $_FILES['file']['size'] = $_FILES['galleryImage']['size'][$i];

      // Set preference
  $config['upload_path'] = './images/'; 
  $config['allowed_types'] = 'jpg|jpeg|png|gif';
      $config['max_size'] = '5000'; // max_size in kb
      $config['file_name'] = $_FILES['galleryImage']['name'][$i];

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

      // File upload
      if($this->upload->do_upload('file')){
        // Get data about the file
        $uploadData = $this->upload->data();
        $filename = $uploadData['file_name'];

        // Initialize array
        //$data['filenames'][] = $filename;

        $color=array(
         "pageId"=>$info["pageId"],
         "meta_key"=>"gImage",
         "meta_value"=>$filename,
         "status"=>1
       );
        $insert=$this->pm->insert_data($table,$color);
      }
    }

  }
$info=$this->input->post();
$data=array();
//如果文件上传表单已提交
$countfiles=计数($_文件['galleryImage']['name']);
对于($i=0;$iload->library('upload',$config));
//文件上传
如果($this->upload->do_upload('file')){
//获取有关该文件的数据
$uploadData=$this->upload->data();
$filename=$uploadData['file_name'];
//初始化数组
//$data['filename'][]=$filename;
$color=数组(
“pageId”=>$info[“pageId”],
“meta_key”=>“gImage”,
“meta_值”=>$filename,
“状态”=>1
);
$insert=$this->pm->insert\u数据($table,$color);
}
}
}
而视图代码是

 <?php
$url=site_url('pages/SavePageAttribute');
$options = array('class' => 'form-inline', 'id' => 'category', 'method' => 'post','style'=>'margin:10px');
echo form_open_multipart($url, $options);
?>
  <tr>
     <td> 
      <?php
         echo form_label('Gallery Image', 'galleryImage'); ?></td>
        <td> 
        <input class="form-control" type="file" name="galleryImage[]" id="galleryImage" multiple="true">
         </td>
       </tr>
<?php echo form_close(); ?>

使用移动上传的文件()上传多个文件

$filename = array();
for($i=0;$i<count($_FILES['attatchments']['name']);$i++){

if(!empty($_FILES['attatchments']['name'][$i])){
 move_uploaded_file($_FILES['attatchments']['tmp_name'][$i],
'assets/attachments'.$_FILES['attatchments']['name'][$i]);
 $filename[$i] = $_FILES['attatchments']['name'][$i];
 }
}
$filename=array();
对于($i=0;$iso),您将返回
“status”false
?这意味着$doc不返回任何内容,这意味着您需要在模型
receipt\m
中分析函数
saveReceipt\m()
,请添加相关代码。。。