Php 使用CI上载文件图像
在我看来,我使用了Php 使用CI上载文件图像,php,codeigniter,file-upload,Php,Codeigniter,File Upload,在我看来,我使用了表单\u open\u multipart(),我有: <input type="file" name="user_photo" style="margin-top: 5px;" /> 我的控制器中有如下配置: $config['upload_path'] = './resources/uploads/'; $config['allowed_types'] = 'jpg|gif|png|bmp|jpeg'; $config['max_size'] = '0';
表单\u open\u multipart()
,我有:
<input type="file" name="user_photo" style="margin-top: 5px;" />
我的控制器中有如下配置:
$config['upload_path'] = './resources/uploads/';
$config['allowed_types'] = 'jpg|gif|png|bmp|jpeg';
$config['max_size'] = '0';
$config['max_width'] = '0';
$config['max_height'] = '0';
$this->load->library('upload', $config);
if(!$this->upload->do_upload('user_photo')) {
echo $this->upload->display_errors('<p>', '</p>');
} else {
echo "<pre>"; print_r($this->upload->data());
}
$config['upload_path']='。/resources/uploads/;
$config['allowed_types']='jpg | gif | png | bmp | jpeg';
$config['max_size']='0';
$config['max_width']='0';
$config['max_height']='0';
$this->load->library('upload',$config);
如果(!$this->upload->do_upload('user_photo')){
echo$this->upload->display_错误(“”,“”);
}否则{
echo”“;print_r($this->upload->data());
}
但是,当我尝试上载文件类型为*.jpg的图像文件时,我遇到了如下错误:不允许您尝试上载的文件类型。
我的配置有任何错误吗,。?
谢谢。如果您的web服务器使用的是PHPV5.2.x,而您使用的是CodeIgniter 2.1.0,请降级回CodeIgniter 2.0.3,上传问题应该会消失 在CodeIgniter 2.1.0中造成此问题的错误代码是
在
/system/libraries/Upload.php
中。有关更多信息,请参阅CodeIgniter的列表 您使用的是哪个版本的CodeIgniter,您使用的web服务器是哪个版本的PHP?您在配置中使用的是:$config['file_name']吗?@stealthyninja我使用的是CodeIgniter 2.1.0和PHP 5.3.0。@Sudhir不,我只是将配置如上所示。。是的,我在CodeIgniter 2.0.3中尝试过,这就是工作,。谢谢
$this->file_type = @mime_content_type($file['tmp_name']);