【问题标题】:PDF File not uploadingPDF文件没有上传
【发布时间】:2016-10-21 10:53:55
【问题描述】:

我有一个同名的输入字段。 pdf[] 我正在将它插入并上传到数据库中,它完美地插入到数据库中。但没有上传到 uploads 文件夹 do_upload(); 有问题

  $items=$_FILES['pdf']['name']; 
  $count = count($items);
  $lstid=$this->FetchData->getLastInserted();
  for($i=0; $i<=$count-1; $i++){
      //echo $img[$i];
      $img = $_FILES['pdf']['name'][$i];
      $timezone = new DateTimeZone('Asia/Calcutta');
      $datetime = new DateTime("now", $timezone);
      $date = $datetime->format("D_M_d_Y_H_i_s");
      $ext = pathinfo($img, PATHINFO_EXTENSION);
      $new_name=$i.'_'.$state_id.'_'.$date;
      if(!empty($img)){
         $imagenamefordatabase = $new_name.'.'.$ext;
      }
      else{
         $imagenamefordatabase ='';
      }
      $config['upload_path'] = 'uploads/';
      // set the filter image types
      $config['allowed_types'] = 'pdf';
      $config['file_name'] = $new_name;
      //load the upload library
      $this->load->library('upload', $config);
      $this->upload->initialize($config);
      $this->upload->set_allowed_types('*');
      $data['upload_data'] = '';
      //if not successful, set the error message
      if (!$this->upload->do_upload('pdf[]')) {
         $data = array('Success' => $this->upload->display_errors());
      } 
      else { 
         //else, set the success message
         $data = array('Success' => "Upload success!");
         $data['upload_data'] = $this->upload->data();
      }
      $sampleresult = array(
        'Report_Print_Data_Id' => $lstid,

        'Sample_Report' => $imagenamefordatabase
      );

      $this->AddData->addReportResult($sampleresult);
  }

【问题讨论】:

  • 请分享$this-&gt;upload-&gt;do_upload方法定义。
  • @jeroen 这是我的正确代码。我必须上传多个文件,输入名称相同。 pdf[] 由于保存了不同名称的文件,我得到了扩展名。在我使用代码 Igniter 的上传库之后。然后将名称保存到 MySQL 数据库中。
  • @NareshKumarNakka $this->upload->do_upload() 是 codeigniter 默认库。
  • 你需要这样使用 $this->upload->do_upload('pdf');
  • 是的,我用过但没有上传。当我有单个输入名称时。 pdf 然后当我将其更改为 pdf[] 然后不上传时它正在工作。出现错误您没有选择要上传的文件。

标签: php codeigniter file-upload codeigniter-3


【解决方案1】:

将文件名更改为用户文件。

在控制器中配置文件大小并尝试。

如有错误请指出。

【讨论】:

  • 感谢您的回复。我解决了答案。声明上面的变量 for 循环。 files=$_FILE; 和 for 循环内 __ $_FILES['pdf']['name']=$files['pdf']['name'][$i];__ 和 do_upload ('pdf');
【解决方案2】:

您必须只传递不带大括号[] 的字段名称。更新代码的以下部分。

if (!$this->upload->do_upload('pdf')) {
     $data = array('Success' => $this->upload->display_errors());
} 
else 
{ 
     //else, set the success message
     $data = array('Success' => "Upload success!");
     $data['upload_data'] = $this->upload->data();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-02
    • 2018-05-07
    • 2011-06-29
    • 1970-01-01
    • 2011-12-08
    • 1970-01-01
    相关资源
    最近更新 更多