增加上传图片日志
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
require_once APPPATH . 'controllers/pingan/BaseController.php';
|
||||
|
||||
/**
|
||||
@@ -17,11 +17,15 @@ class Upload extends BaseController
|
||||
|
||||
public function index_post()
|
||||
{
|
||||
$logPath = 'pingan';
|
||||
$logFile = 'upload.txt';
|
||||
$file = $_FILES['file'];
|
||||
if (!$file) {
|
||||
debug_log("未选择图片", $logFile, $logPath);
|
||||
$this->return_json('请选择图片');
|
||||
}
|
||||
if (!$file['tmp_name']) {//太大的图片上传,这个参数会变成空的
|
||||
debug_log("图片太大获取不到图片信息", $logFile, $logPath);
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
if (!file_exists(TEMP_PATH)) {
|
||||
@@ -32,11 +36,13 @@ class Upload extends BaseController
|
||||
$tmp = TEMP_PATH . md5($file['name'] . uniqid()) . substr($file['name'], strpos($file['name'], '.', strlen($file['name']) - 1));
|
||||
move_uploaded_file($file['tmp_name'], $tmp);
|
||||
if (!filesize($tmp)) {
|
||||
debug_log("图片太大获取不到图片信息1", $logFile, $logPath);
|
||||
$this->return_json('图片有点问题,换个小的试试');
|
||||
}
|
||||
//上传图片到FTP
|
||||
$res = $this->upload_img_qiniu($tmp, "pingan/");
|
||||
if (!$res) {
|
||||
debug_log("七牛上传图片失败:" . json_encode($res, JSON_UNESCAPED_UNICODE), $logFile, $logPath);
|
||||
$this->return_json('上传失败');
|
||||
}
|
||||
$data['full_url'] = build_qiniu_image_url($res['photo']);
|
||||
@@ -53,6 +59,8 @@ class Upload extends BaseController
|
||||
*/
|
||||
private function upload_img_qiniu($file, $path = '', $filename = '')
|
||||
{
|
||||
$logPath = 'pingan';
|
||||
$logFile = 'upload.txt';
|
||||
$phoId = md5(uniqid() . mt_rand(0, 10000) . time());
|
||||
$filename = $filename ? $filename : $file;
|
||||
$ext_arr = explode(".", $filename);
|
||||
@@ -73,11 +81,12 @@ class Upload extends BaseController
|
||||
$img_size = getimagesize($oriPath);
|
||||
$file_size = filesize($oriPath);
|
||||
$size = "{$img_size[0]},{$img_size[1]},{$file_size}";
|
||||
unlink($oriPath);
|
||||
if ($res) {
|
||||
unlink($oriPath);
|
||||
$size = getimagesize($res['url']);
|
||||
return array('photo' => $res['file'], 'size' => $size);
|
||||
} else {
|
||||
debug_log("原始图片文件:" . $oriPath, $logFile, $logPath);
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user