我的upload_form.php脚本
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<!--<form action="" method="post">-->
<?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"/>
<?php
form_close();
?>
</body>Upload.php内部控制器
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Upload extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(['form', 'url']);
}
public function index()
{
$this->load->view('upload_form', ['error' => ' ']);
}
public function do_upload()
{
$config = [
'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 = ['error' => $this->upload->display_errors()];
$this->load->view('upload_form', $error);
} else {
$data = ['upload_data' => $this->upload->data()];
$this->load->view('upload_success', $data);
}
}
}如果没有选择文件,它会给出适当的错误。但在选择其他文件(文本或图像)时,没有给出错误。仅显示空白页
移动上传的文件正在运行。
上传成功
<html>
<head>
<title>Upload Form</title>
</head>
<body>
<h3>Your file was successfully uploaded!</h3>
<ul>
<?php foreach ($upload_data as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
<p><?php echo anchor('upload', 'Upload Another File!'); ?></p>
</body>
</html>发布于 2017-01-04 19:00:28
尝试如下所示..
public function do_upload()
{
$config = [
'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 = ['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);
}
}}
发布于 2017-01-04 19:27:43
查看此代码
if ($_FILES['inputname']['name'] != "") { $config['upload_path'] = './uploads/'; $config['allowed_types'] = 'gif|jpg|png'; $config['max_size'] = '10000'; $this->load->library('upload', $config); }
发布于 2019-05-20 16:15:27
我也遇到过同样的问题,但是当我将代码从
$this->load->library('upload',$config);至
$this->load->library('upload');
$this->upload->initialize($config);那么我的代码就可以正常工作了。试一试,它可能会对你有帮助。谢谢。
https://stackoverflow.com/questions/41461966
复制相似问题