【发布时间】:2017-12-31 11:04:41
【问题描述】:
我正在尝试通过网络服务上传一张图片。以下是代码
public function upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|mp4|jpeg';
$config['max_size'] = 100;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->data['data']= $_FILES;
echo json_encode($this->data); die;
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->data['data']= $error ;
echo json_encode($this->data['data']);
die;
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->data['data']= 'done' ;
echo json_encode($this->data['data']);
die;
}
}
如果我json_encode($_FILES)这是手机上的回复
data = {
userfile = {
error = 0;
name = pen;
size = 38238;
"tmp_name" = "/tmp/phpEsEQNK";
type = jpeg;
};
};
当我打印错误数组时,这就是我得到的
error = "<p>The filetype you are attempting to upload is not allowed.</p>";
请检查打印的两个回复,并告诉我如何解决这个问题。
【问题讨论】:
标签: php codeigniter