protected static function _publicUpload($file_type = null, $name = null, $file_name = null, $dir_id = null, $is_mobile = 0, $uid) { global $upload_config; $type_id = null; foreach ($upload_config as $key => $value) { if (strstr($value, strtolower($file_type))) { $type_id = $key; break; } } //判断文件是否已存在 // if( function_exists( 'com_create_guid' ) ){ // $upload_path = com_create_guid();//函数com_create_guid在linux centos6.5不支持,可能没配置 // }else{ // $upload_path = md5( $path . $file_name ); // } $path = ROOT_PATH . PhotoM::uploadPath . $uid . '/' . $type_id . '/' . $dir_id . '/'; $upload_path = md5($path . $file_name . $file_type . time()); $save = $path . $upload_path . '.' . $file_type; if ($type_id && !is_file($path . $upload_path . '.' . $file_type)) { //目录不存在,创建目录 if (!is_dir($path)) { mkdir($path, 0755, true); } if (!move_uploaded_file($name, $save)) { throw new Exception('exit'); } $data['uid'] = $uid; $data['dir_id'] = $dir_id; $data['type_id'] = $type_id; $data['file_name'] = $file_name; $data['file_type'] = $file_type; $data['upload_path'] = $uid . '/' . $type_id . '/' . $dir_id . '/' . $upload_path . '.' . $file_type; $results_upload = UploadFile::addUploadFile($data); //缓存上传的图片(缩放后的图片) $cache_dir = '/temp/photo/' . $data['uid'] . '/' . $data['type_id'] . '/' . $data['dir_id'] . '/'; PhotoM::_cachePhoto($cache_dir, $data['upload_path'], $file_type); //删除redis缓存的数据 $key_footer = 'uploadFileListByDir_' . $uid . '_' . $dir_id; Cache::del($key_footer); if ($is_mobile) { return true; } else { $data1['id'] = $results_upload; return $data1; } } }