繁体   English   中英

在Codeigniter中上传文件

[英]File Upload in Codeigniter

我正在尝试使用代码点火器上传图像,但是这是不可能的,为什么我不知道。 谁能帮我?

“我将打印$ _FILES数组”

这是我尝试过的代码

 public function upload(){
 $config['upload_path'] = "./assets/uploads/"; 
 $config['allowed_types'] = "jpg|png|jpeg|gif"; 
 $this->load->library("upload" , $config);

 $rs = $this->upload->do_upload("userfile"); 
 print_r($rs); 
 print_r($_FILES); 

if(!$rs){ 
$error = array('error'=>$this->upload->display_errors());
$this->load->view("main_view", $error); 

}
else{ 
$file_data = $this->upload->data(); $data['img'] = "localhost/FileUpload/assets/uploads/";
$file_data['file_name']; $this->load->view("success_msg" , $data); 
  } 
} 

我当然不能实际测试,但是我相信这会让您入门。

public function upload() {

  $name = 'something'; // set this based on your requirements, I often use random strings or user names according to the situation. 

  $config['upload_path']   = "assets/uploads/"; 
  $config['allowed_types'] = "jpg|png|jpeg|gif";
  $config['file_name']     = $name;

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

  $rs = $this->upload->do_upload("userfile"); 

  print_r($rs); 
  print_r($_FILES); 

  if(!$rs) { 
    $error = array( 'error'=>$this->upload->display_errors() );
    $this->load->view("main_view", $error); 
  }
  else { 
    $file_data = $this->upload->data();
    $file_name = $file_data['file_name'];
    $ext       = pathinfo($file_name, PATHINFO_EXTENSION); //Useful to store your name in database if/when you need to
    $data      = array('upload_data' => $upload_data);
    $this->load->view("success_msg" , $data); 
 } 

} 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM