我知道这可能是重复但我需要更多的帮助。 我已经开始在codeigniter中为android应用程序制作api了。目前正致力于制作api以上传图片..我正在使用https://github.com/chriskacerguis/codeigniter-restserver 使用邮递员上传图像来测试我的API但是 但我得到的东西像
' ------ WebKitFormBoundaryXkKFa0QV2XVs0EoK 内容处置:_form数据; _name' => string'" filesss&#34 ;;文件名=" 17264394_1739947152983817_1705887364349350305_n.jpg" 内容类型:image / jpeg �����JFIF����������Photoshop3.0�8BIM������g�Vnlfejt43YHm4REx3e4k(�bFBMD01000abe0300002f19000082320000643300004b3400002f4d0000c46f0000d3750000b8780000b07b000096cd0000��ICC_PROFILE���lcms��mntrRGBXYZ
现在任何人都可以帮助我如何在我的服务器上保存图像 下面是我的代码
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . './libraries/REST_Controller.php';
use Restserver\Libraries\REST_Controller;
class Update_image extends REST_Controller{
function __construct(){
parent::__construct();
$models[] = 'Quiz_model';
$models[] = 'Users_model';
$this->load->model($models);
$libs[] = 'form_validation';
$libs[] = 'image_lib';
$libs[] = 'email';
//$libs[] = 'rest';
$this->load->library($libs);
$helpers[] = 'file';
$helpers[] = 'security';
$helpers[] = 'url';
$helpers[] = 'string';
$this->load->helper($helpers);
}
function index_post(){
$users_id = $this->input->post('users_id');
$users_id = 6;
$config['upload_path'] = './public/user_images/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = ; // for 5mb file
$config['max_width'] = 5000;
$config['max_height'] = 5000;
$this->load->library('upload', $config);
if(!$this->upload->do_upload('users_image')){
$error = array('error' => $this->upload->display_errors('<span>','<span>'));
$data['msg'] = error('Please Fix the errors below');
$data['file_upload_error'] = formErrorParse($this->upload->display_errors());
$this->form_validation->set_message('quiz_image', implode('<br/>', $error));
$response['status'] = 0;
$response['msg'] = strip_tags($this->upload->display_errors());
}else{
$uploadStat = $this->upload->data();
$img_config['image_library'] = 'gd2';
$img_config['source_image'] = './public/uploads/user_images/'.$uploadStat['file_name'];
$img_config['new_image'] = './public/uploads/user_images/thumbnail/'.$uploadStat['file_name'];
//$img_config['create_thumb'] = TRUE;
$img_config['maintain_ratio'] = TRUE;
$img_config['width'] = 150;
$img_config['height'] = 150;
$this->image_lib->clear();
$this->image_lib->initialize($img_config);
$this->image_lib->resize();
$updates['users_images'] = $uploadStat['file_name'];
$cond['users_id'] = $users_id;
$this->db->update('users', $updates, $cond);
$response['status'] = 1;
$response['msg'] = 'Image Uploaded';
}
$this->response($response, 200);
}
}
答案 0 :(得分:1)
我和你有完全相同的问题。 但是在postman中从头文件中删除Content-Type后解决了。 然后你将获得$ _FILES中的数据。
答案 1 :(得分:0)
确保你的php版本是5.6或更高版本,我有同样的问题,并通过切换到PHP版本7来解决它。