我正在使用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
)
上载路径似乎无效。
配置文件.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";
}
}
索引.php视图
<h2 class="heading">Profile</h2>
<div class="row">
<div class="col-md-3">
<div class="profile-img">
<?php if (!empty($user->photo)): ?>
<img src="/uploads/<?php echo $user->photo; ?>" alt="<?php echo $user->photo; ?>">
<?php endif;?>
<img src="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS52y5aInsxSm31CvHOFHWujqUx_wWTS9iM6s7BAm21oEN_RiGoog" alt=""/>
<?php echo form_open_multipart('admin/profile/do_upload');?>
<div class="file btn btn-lg btn-primary">
<i class="fa fa-pencil-square-o"></i>
<input id="choose_image" type="file" name="filename" />
</div>
<button id="SubmitBtn" type="submit" style="display:none">Upload photo</button>
</form>
</div>
自动加载.php
$autoload['libraries'] = array('database','session','form_validation','encryption','upload');
$autoload['helper'] = array('url','form', 'file');
我已经尝试了几种解决方案,但仍然得到相同的错误。
4条答案
按热度按时间dxpyg8gm1#
是否尝试在执行do_upload之前初始化配置项文件上载类?
我通常用这个
qvtsj1bj2#
我认为上传路径应该是“./application”
btqmn9zl3#
c9qzyr3d4#
我也有同样的问题,但我的是一个打字错误。
而不是使用这个
由于复制和粘贴,我不小心使用了此功能
我花了几个小时才弄明白这一点,我希望我帮助了一些人。