我的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>
答案 0 :(得分:0)
尝试如下..
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);
}
}
}
答案 1 :(得分:0)
检查此代码
if ($_FILES['inputname']['name'] != "") {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '10000';
$this->load->library('upload', $config);
}
答案 2 :(得分:0)
我也遇到过同样的问题,但是当我更改代码时
spring.cloud.kubernetes.reload.enabled: true
到
$this->load->library('upload',$config);
然后我的代码工作正常。尝试一次对您可能会有帮助。谢谢。