【发布时间】:2017-08-21 08:25:51
【问题描述】:
我知道它可能是重复的,但我需要更多帮助。 我已经开始在 codeigniter 中为 android 应用程序制作 api。目前正在制作用于上传图像的api..我正在使用https://github.com/chriskacerguis/codeigniter-restserver 使用邮递员上传图片来测试我的 API 但是 但我得到了类似的东西
'-----WebKitFormBoundaryXkKFa0QV2XVs0EoK
Content-Disposition:_form-data;_name' => string '"filess";文件名="17264394_1739947152983817_1705887364349350305_n.jpg"
内容类型:图片/jpeg
�����JFIF����������PHOWSHOP3.0�8BIM������G�VNLFEJT43YHM4REX3E4K(�BFBMD01000ABE0300002F19000082320078008580C4603CD0000334002F4D00600C46CF4D000033400002F4D00600C46CF4D0000C46CF4D00600C4652F4D00600C463300D0000C46F0000B07B00346500B07B003400002F4D0000C46500D3750000B87800D37500C4652FCD0000│IC_PROFILEȱLCMS│MNTRRGBXYZ EM> P. >
现在任何人都可以帮助我如何将图像保存在我的服务器上
下面是我的代码<?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);
}
}
【问题讨论】:
-
有错误我们可以帮忙解决吗?
-
没有错误。
-
如果你 var_dump($uploadStat);die;此时只需遵循基本的 php 调试策略即可。
-
我已经完成了所有这些。 $_FILES 变量为空,这就是为什么在上传 codeigniter 类时没有收到文件
-
您的表单有 'enctype='multipart/form-data'?在调用控制器方法之前,问题必须存在。
标签: php android codeigniter