我想通過網絡服務上傳一張圖片。以下是代碼Codeingiter:通過網絡服務上傳圖片
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>";
請檢查印刷兩種反應並讓我知道我該如何解決這個問題。
檢查以下門票:https://stackoverflow.com/questions/9815208/codeigniter-the-filetype-you-are-attempting-to-upload-is - 不允許 –