当我尝试上传一张图片,它不是在所有上传和我的代码是在这里文件上传被失败
public function image_upload($path)
{
if($_FILES)
{
$config['upload_path'] = './uploads/'.$path.'/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '5000';
$config['max_width'] = '4000';
$config['max_height'] = '6500';
$config['file_name'] ='img';
$this->load->library('upload', $config);
if(! $this->upload->do_upload("file"))
{
$this->session->set_flashdata('message',$this->upload->display_errors());
return false;
}
else
{
$config['image_library'] = 'gd2';
$config['source_image'] = './uploads/'.$path.'/'.$this->upload->file_name;
$config['create_thumb'] = FALSE;
$config['maintain_ratio'] = FALSE;
$config['width'] = 200;
$config['height'] = 150;
$config['new_image'] = './uploads/'.$path.'/thumb/';
$this->load->library('image_lib',$config);
if(! $this->image_lib->resize())
{
$this->session->set_flashdata('message',$this->image_lib->display_errors());
return false;
}
else
{
return $this->upload->file_name;
}
}
}
}
我认为页是
<form role="form" action="<?php echo base_url();?>admin/add_staff" method="post" enctype="multipart/form-data">
<tr>
<td>Photo</td>
<td><input type="file" id="file" name="file"></td>
</tr>
<tr>
<td></td>
<td> <input class="btn btn-primary save-btn" type="submit" value="Save" > </td>
</tr>
</form>
我cntroller看起来像这样
public function add_staff()
{
$data['active_mn'] = 'add_staff';
if($_POST)
{
$this->form_validation->set_rules('name', 'Name', 'required');
if($this->form_validation->run() == true)
{
if(! $this->image_upload($path = 'staff'))
{
$photo = '';
}
else
{
$photo = $this->upload->file_name;
}
$data = array('photo'=>$photo);
$status = $this->admin_model->db_insert($table='staff',$data);
if($status)
{
$this->session->set_flashdata('message','Staff added Successfully');
}
else
{
$this->session->set_flashdata('message','Insertion failed');
}
redirect('admin/view_staff');
}
}
$this->load->view('admin/add_staff',$data);
}
我已经经历了几种方式,但没有得到解决这个问题。会是系统文件的问题吗?
而你用来从$ _FILES ['file'] ['tmp_name'];'获取文件的代码在哪里?哪个是物理phile(双关语意思) – ArtisticPhoenix
检查您试图上传的图像大小。在PHP默认是8M,如果你尝试上传超过这个限制,它不会上传。如果你想增加上传限制改变php.ini新的限制 – Veer
不,我使用的图像大小只有不到8M –