【发布时间】:2017-01-26 19:37:54
【问题描述】:
我正在尝试使用代码点火器上传图像,但它没有显示任何成功失败消息。 请帮忙。
这是一个文件上传表单
查看- Upload_form.php
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<form action="" method="">
<?php echo $error; ?>
<?php echo form_open_multipart('upload/do_upload');?>
<input type="file" name="userfile" size="20" />
<br><br>
<input type="submit" value="upload"/>
</form>
</body>
</html>
这是查看成功文件
查看 - upload_success.php
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Upload form</title>
</head>
<body>
<h1> YOUR FILE WAS SUCCESSFULLY UPLOADED </h1>
<ul>
<?php foreach ($upload_data as $item => $value); ?>
<li><?php echo $item; ?> : <?php echo $value; ?></li>
<?phpendforeach ;?>
</ul>
<?php echo anchor('upload','upload Another file'); ?>
</body>
</html>
这是一个控制器文件。
控制器 - upload.php
<?php
class Upload extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper (array('form','url'));
}
public function index(){
$this->load->view('Upload_form',array('error'=>' '));
}
public function do_upload(){
$config = array(
'upload_path' => './uploads/',
'allowed_types' => 'gif|jpg|png',
'max_size' => 100,
'max_width' => 1024, //Mainly goes with images only
'max_heigth' => 768
);
$this->load->library('upload',$config);
if(!$this->upload->do_upload('userfile')) {
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form',$error);
}
else{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success',$data);
}
}
}
我已经在代码点火器的根目录中创建了上传文件夹。
【问题讨论】:
-
你应该使用form_open_multipart codeigniter.com/user_guide/helpers/…最好使用form helper
-
请删除代码中的