Front-End-Code
<html> <form action="ci/CodeIgniter_2.2.0/index.php/upload/up" method="post" enctype="multipart/form-data"> <input type="file" name="upfile" /> <input type="submit" name="sub" value="提交" /> </form> </html>
Controller:
Definieren Sie ein Array und legen Sie einige Upload-bezogene Parameter fest
$config['upload_path'] = './uploads/'; //设置允许上传的类型 $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; //如果是图片还可以设置最大高度和宽度 $config['max_height'] = 768; $config['max_width'] = 1024;
Rufen Sie die allgemeine Upload-Klasse von CI auf Führen Sie den Upload aus
//upload为调用的类名,全小写 $this->load->library('upload',$config); //如果上传框的name写的是userfile,那就不用传参数了,如果不是,把name的值传进去 $this->upload->do_upload('上传框的name');
Fehler- oder Erfolgsmeldung erhalten
//出错信息 $error = array('error' => $this->upload->display_error()); //成功信息 $data = array('upload_data' => $this->upload->data());
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Upload extends CI_Controller { //显示带表单的视图 public function index(){ $this->load->view('up'); } //显示上传信息 public function up(){ $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = "2000"; $this->load->library('upload',$config); //打印成功或错误的信息 if($this->upload->do_upload('upfile')) { $data = array("upload_data" => $this->upload->data()); var_dump($data); } else { $error = array("error" => $this->upload->display_errors()); var_dump($error); } } }
Front-End-Code
<html> <form action="ci/CodeIgniter_2.2.0/index.php/upload/up" method="post" enctype="multipart/form-data"> <input type="file" name="upfile" /> <input type="submit" name="sub" value="提交" /> </form> </html>
Controller:
Definieren Sie ein Array und legen Sie einige Upload-bezogene Parameter fest
$config['upload_path'] = './uploads/'; //设置允许上传的类型 $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '100'; //如果是图片还可以设置最大高度和宽度 $config['max_height'] = 768; $config['max_width'] = 1024;
Rufen Sie die allgemeine Upload-Klasse von CI auf und führen Sie den Upload aus
//upload为调用的类名,全小写 $this->load->library('upload',$config); //如果上传框的name写的是userfile,那就不用传参数了,如果不是,把name的值传进去 $this->upload->do_upload('上传框的name');
Erhalten Sie Fehler- oder Erfolgsinformationen
//出错信息 $error = array('error' => $this->upload->display_error()); //成功信息 $data = array('upload_data' => $this->upload->data());
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); class Upload extends CI_Controller { //显示带表单的视图 public function index(){ $this->load->view('up'); } //显示上传信息 public function up(){ $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = "2000"; $this->load->library('upload',$config); //打印成功或错误的信息 if($this->upload->do_upload('upfile')) { $data = array("upload_data" => $this->upload->data()); var_dump($data); } else { $error = array("error" => $this->upload->display_errors()); var_dump($error); } } }
Mehr im CI-Framework Bitte zahlen Sie Beachten Sie die chinesische PHP-Website für verwandte Artikel zum Hochladen von Bildern!