我正在使用 php codeigniter 框架,并尝试上传文件夹中的图像并在配置文件视图中显示,但这是我上传文件时得到的结果:- Array ( [upload_path] => ./community/photos/ [allowed_types] => jpeg|jpg|png [max_size] => 100 [max_width] => 1024 [max_height] => 768 [overwrite] => 1 [file_name] => 1600052487_Musical-Birthday-Candle-Magic-Lotus-Flower-Candles-Blossom-Rotating-Spin-Party-Candle-14Small-Candles-2layers-Cake.jpg ) 上传路径似乎无效。profile.php 控制器public function do_upload() { echo "<pre>"; //print_r($_FILES); //die; if(!empty($_FILES['filename']['name'])){ $config['upload_path'] = FCPATH.'application/'; $config['allowed_types'] = 'jpeg|jpg|png'; $config['max_size'] = 100; $config['max_width'] = 1024; $config['max_height'] = 768; $config['overwrite'] = true; $config['file_name'] = time().'_'.$_FILES['filename']['name']; print_r($config); //echo var_dump(is_dir(FCPATH.'uploads/')); //die; $this->load->library('upload', $config); if ( ! $this->upload->do_upload('filename')) { //echo "sdfs"; print_r($this->upload->display_errors()); die; // $error = array('error' => $this->upload->display_errors()); $this->session->set_flashdata ('success','Invalid Credentils'); redirect('myProfile'); // $this->load->view('admin/profile/index', $error); } else { echo "xcvcx"; die; $data = array('user_profile' => $this->upload->data()); $this->load->view('admin/profile/index', $data); } }else{ echo "dfgfd"; } }
4 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
您是否尝试在执行 do_upload 之前初始化 CI 文件上传类?。
我通常用这个
$this->upload->initialize($set_upload);//my func class for config //generally they use $this->upload->initialize() if (!$this->upload->do_upload('userfile')){ }
噜噜哒
TA贡献1784条经验 获得超7个赞
我也遇到了同样的问题,但我的是一个拼写错误。
而不是使用这个
$this->upload->initialize($config);
由于复制和粘贴,我不小心使用了这个
$this->load->initialize($config);
我花了几个小时才弄清楚这一点。我希望我帮助了某人。
慕姐4208626
TA贡献1852条经验 获得超7个赞
<?php if (!empty($user->photo)): ?>
<img src="<?php echo base_url('uploads/'.$user->photo;);?>" alt="<?php echo $user->photo; ?>">
<?php endif;?>
- 4 回答
- 0 关注
- 113 浏览
添加回答
举报
0/150
提交
取消