'123','image1'=>'@/path/to/file','image2'=>'@/path/to/file'] * @return mixed */ public static function upload($url, $data = []) { if (function_exists('curl_file_create')) { foreach ($data as $k => $v) { if (strpos($v, '@') === 0) { $data[$k] = curl_file_create(trim($v, '@')); } } } $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); self::$response = curl_exec($ch); self::$curl_errno = curl_errno($ch); self::$curl_error = curl_error($ch); self::$curl_info = curl_getinfo($ch); curl_close($ch); if (self::$auto_redirect && in_array(self::$curl_info['http_code'], [301, 302])) { return self::upload(self::$curl_info['redirect_url'], $data); } return self::$response; } /** * 根据路径或网址格式获取文件名 * @param string $str 例:http://a.com/filename.txt或/home/filename.txt * @return mixed|null */ public static function getFileName($str) { if ($str === '' || $str === null) { return null; } $names = mb_split('/', $str); if (!is_array($names)) { return null; } return $names[count($names) - 1]; } /** * 根据文件名或文件路径获取文件后缀 * @param $str * @return mixed|null */ public static function getFileExtension($str) { $str = self::getFileName($str); if ($str === '' || $str === null) { return null; } $names = mb_split('\.', $str); if (!is_array($names)) { return null; } if (count($names) == 1) { return ''; } return $names[count($names) - 1]; } }