用户
 找回密码
 入住 CI 中国社区
搜索
查看: 6443|回复: 7
收起左侧

[HELP] 文件上存不了?

[复制链接]
发表于 2009-8-12 21:58:23 | 显示全部楼层 |阅读模式
这是我的控制器 welcome.php

<?php
class Welcome extends Controller {
function Welcome()
{
  parent::Controller();
}

function index()
{
  $this->load->view('welcome_message');
}
function do_upload(){
  $this->data['c_page'] = base_url();
  $config['upload_path'] = $this->data['c_page'].'uploads/';
  $config['allowed_types'] = 'gif|jpg|png';
  $this->load->library('upload',$config);
   if ( ! $this->upload->do_upload())
       {   $this->data['error'] = array('error' => $this->upload->display_errors());
         $this->load->view('welcome_message',$this->data);
       }else{
         $this->data['data'] = array('upload_data' => $this->upload->data());
        $this->load->view('welcome_message',$this->data);
         }
    }
}
?>
-----------------------------------------------------------------------------
这是我的输出页面 welcome_message.php
<?php echo form_open_multipart('welcome/do_upload',array('name'=>'test','method'=>'post'))?>
<input type="file" name="filename">
<input type="submit" value="upload">
</form>
<?php
if (isset($error)) {
var_dump($error);
}
echo "<br>";
if (isset($data)) {
var_dump($data);
}
?>

----------------------------------------------------------------------------
文件的权限我也设为777了,我也在配置config.php里自动加载了url和form的帮助功能,可点上存后,还是打印出这个错误
array(1) { ["error"]=> string(43) "
You did not select a file to upload.
" }

有点郁闷,版主大大们帮看看咋回事。
发表于 2009-8-12 22:21:16 | 显示全部楼层
<input type="file" name="filename">
改成
<input type="file" name="userfile">
发表于 2009-8-12 23:23:43 | 显示全部楼层
版主回答的没错。

大家都不喜欢“仔细”看手册吗?仔细是一个程序员应有的素质。
发表于 2009-8-13 09:19:24 | 显示全部楼层
看看我的帖子,你就明白了

http://codeigniter.org.cn/forums/thread-2875-1-1.html
发表于 2009-9-3 15:16:52 | 显示全部楼层
$this->upload->do_upload('filename')
发表于 2013-5-31 08:58:37 | 显示全部楼层
我写了 <input type="file" name="userfile"   id="face" />而且if( !$this->upload->do_upload("userfile")){...也写了还是会报you did not select a  file to upload
发表于 2013-6-13 01:02:46 | 显示全部楼层
form要加上
enctype="multipart/form-data"
发表于 2014-3-16 08:49:55 | 显示全部楼层
看下源码$this->upload->do_upload 你就知道原因了。

本版积分规则