作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在 View 中
<?php echo form_open_multipart('welcome/do_upload');?>
<input type="file" name="userfile" size="20" />
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = TRUE;
$config['encrypt_name'] = FALSE;
$config['remove_spaces'] = TRUE;
if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile')) {
echo 'error';
} else {
return array('upload_data' => $this->upload->data());
}
}
$this->data['data'] = $this->do_upload();
<ul>
<?php foreach ($data['upload_data'] as $item => $value):?>
<li><?php echo $item;?>: <?php echo $value;?></li>
<?php endforeach; ?>
</ul>
最佳答案
看来问题是您将表单请求发送到 welcome/do_upload
,并调用Welcome::do_upload()
$this->do_upload()
的另一种方法.
因此,当您调用 $this->do_upload();
在您的第二种方法 , $_FILES
数组将是 空 .
这就是为什么var_dump($data['upload_data']);
返回 NULL
.
如果你想从 welcome/second_method
上传文件, 将表单请求发送至 欢迎/second_method 您在哪里调用 $this->do_upload();
.
然后更改表单辅助函数(在 View 内)如下1:
// Change the 'second_method' to your method name
echo form_open_multipart('welcome/second_method');
url
和
form
使用 CodeIgniter 示例代码之前的辅助函数:
// Load the helper files within the Controller
$this->load->helper('form');
$this->load->helper('url');
// Load the helper files within the application/config/autoload
$autoload['helper'] = array('form', 'url');
关于codeigniter - 如何在 CodeIgniter 中上传图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17315962/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!