我正在尝试使用代码点火器上传图像,但它没有显示任何失败消息的成功 . 请帮忙 .
This is a file upload form
view- 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>
This is a view success file
view - 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>
This is a controller file.
controller - 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);
}
}
}
我在代码点火器的根目录下创建了uploads文件夹 .
2 回答
请对您的代码 controller 和 view page 进行一些更改 . 还要确保在您的视图 Upload_form 中使用放置在 application folder.below代码之外的 uploads 文件夹
并尝试在控制器中执行以下代码 upload
你的upload_path可能不正确,所以这里是我正在使用的代码:
1.在控制器顶部添加这个以声明upload_path:
2.更改$ config upload_path
至
有关详细信息,请参阅我的uploadProfile控制器: