【发布时间】:2017-01-04 10:48:01
【问题描述】:
我的 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>
在控制器内上传.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>
【问题讨论】:
-
查看代码是什么
upload_success.php。 -
移动上传的文件适用于上传文件夹,所以我认为这不是 777 权限问题。
-
尝试将 'max_size' => 100、'max_width' => 1024、'max_heigth' => 768 的值更改为更多
-
是的,也要检查该文件夹的权限
-
@ – Hikmat Sijapati 编辑
标签: php codeigniter