上传卡券logo图片. $url 为 http://itse.cc/img.jpeg

@param $url

@return array|bool
510043
function curlCardUpload_img($url)
    {
        $node = 'uploadimg';

        $rest      = self::curl_get($url);
        $file_tail = explode("/", $rest['type']);

        /* 判断是不是阿里云服务器 */
        if ($rest['header']['Server'] == 'AliyunOSS') {
            $imgType      = substr($url, strrpos($url, '.') + 1);
            $file_type    = 'image/' . $imgType;
            $file_tail[1] = $imgType;
        } else {
            $file_type = $rest['type'];
        }

        $name      = 'media';
        $file_name = md5(uniqid(rand(1000, 9999))) . '.' . $file_tail[1]; // 设置上传文件名
        $imgSize   = $rest['size'];
        //1M = 1048576字节 微信允许上传的最大文件
        if ($imgSize >= 1048576) {
            $this->setError('文件过大');

            return false;
        }
        // 读取临时文件里 上传文件的信息
        $key = "name=\"{$name}\"; filename=\"{$file_name}\"\r\nContent-Type: {$file_type}\r\n";

        $param       = [];
        $param[$key] = $rest['content'];

        $res = $this->_post($node, $param, false);

        return $res;
    }
976110
public function loadUrl($url)
    {
        // Fetch HTTP content using Guzzle
        $response = $this->client->get($url);

        return $this->loadHtml($response->getBody()->__toString(), $url);
    }
1250714
public function getFromURL($url, $name = false)
    {
        $tmp_path = sys_get_temp_dir() . '/';

        if (Validator::validate(Validator::V_LINK, $url)) {
            $image = getimagesize($url);
            switch ($image['mime']) {
                case 'image/gif':
                case 'image/png':
                case 'image/bmp':
                case 'image/jpeg':
                    if ($image['mime'] == 'image/gif') {
                        $type = '.gif';
                    }
                    if ($image['mime'] == 'image/png') {
                        $type = '.png';
                    }
                    if ($image['mime'] == 'image/bmp') {
                        $type = '.bmp';
                    }
                    if ($image['mime'] == 'image/jpeg') {
                        $type = '.jpg';
                    }

                    if (!$name) {
                        $name = uniqid('post-') . $type;
                    } else {
                        $name .= '-' . uniqid("", true) . $type;
                    }
                    file_put_contents($tmp_path . $name, file_get_contents($url));

                    $this->getFromPath($name, sys_get_temp_dir());
                    $this->width  = $image[0];
                    $this->height = $image[1];

                    return true;
                default:
                    return false;
            }
        }

        return false;
    }
299230
public static function image($url, $name = null, $options = [])
    {
        $options['src'] = $url;

        self::exclure($options);

        return self::input('image', $name, null, $options);
    }
536791
public function image($url)
    {
        list($width, $height) = getimagesize($url);
        $this->pdf->Image($url, '', '', 100);
    }
853724
private function fetchImageContentFromURL($url)
    {
        $data = null;

        if ($stream = fopen($url, 'r')) {
            $data = stream_get_contents($stream);
            fclose($stream);
        }

        return $data;
    }
981034
protected function urlParts(string $url)
    {
        if (false === filter_var($url, FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED)) {
            return false;
        }
        return parse_url($url) ?: false;
    }
574409
protected function fetchAndSaveUniqueImage( $url ) {

		if ( ! filter_var( $url, FILTER_VALIDATE_URL ) ) {
			return '';
		}

		$remote_img_location = $url;

		// Cheap cache
		static $already_done = [];
		if ( isset( $already_done[ $remote_img_location ] ) ) {
			return $already_done[ $remote_img_location ];
		}

		/* Process */

		// Basename without query string
		$filename = explode( '?', basename( $url ) );
		$filename = array_shift( $filename );

		$filename = sanitize_file_name( urldecode( $filename ) );

		if ( ! preg_match( '/\.(jpe?g|gif|png)$/i', $filename ) ) {
			// Unsupported image type
			$already_done[ $remote_img_location ] = '';
			return '';
		}

		$tmp_name = download_url( $remote_img_location );
		if ( is_wp_error( $tmp_name ) ) {
			// Download failed
			$already_done[ $remote_img_location ] = '';
			return '';
		}

		if ( ! \Pressbooks\Image\is_valid_image( $tmp_name, $filename ) ) {

			try { // changing the file name so that extension matches the mime type
				$filename = $this->properImageExtension( $tmp_name, $filename );

				if ( ! \Pressbooks\Image\is_valid_image( $tmp_name, $filename ) ) {
					throw new \Exception( 'Image is corrupt, and file extension matches the mime type' );
				}
			} catch ( \Exception $exc ) {
				// Garbage, don't import
				$already_done[ $remote_img_location ] = '';
				unlink( $tmp_name );
				return '';
			}
		}

		$pid = media_handle_sideload(
			[
				'name' => $filename,
				'tmp_name' => $tmp_name,
			], 0
		);
		$src = wp_get_attachment_url( $pid );
		if ( ! $src ) {
			$src = ''; // Change false to empty string
		}
		$already_done[ $remote_img_location ] = $src;
		@unlink( $tmp_name ); // @codingStandardsIgnoreLine

		return $src;
	}
1019072
public function resolveUrlInCss($url)
    {
        if (substr($url, 0, 2) === '//') {
            // double slashed indicate a fully fledged url like //typo3.org
            return $url;
        }
        if (strpos($url, '://') !== false) {
            // http://, ftp:// etc. should not be touched
            return $url;
        }
        if (substr($url, 0, 1) === '/') {
            if (substr($url, 0, strlen(PATH_site)) === PATH_site) {
                return '../../'.substr($url, strlen(PATH_site));
            }

            return $url;
        }
        if (substr($url, 0, 5) === 'data:') {
            // data:image/svg+xml;base64,... should not be touched
            return $url;
        }
        // anything inside TYPO3 has to be adjusted
        return '../../../../'.dirname($this->removePrefixFromString(PATH_site, $this->inputFilename)).'/'.$url;
    }
473727
protected function parseUrl($url)
    {
        $depr = $this->rule->getConfig('app.pathinfo_depr');
        $bind = $this->rule->getRouter()->getBind();

        if (!empty($bind) && preg_match('/^[a-z]/is', $bind)) {
            $bind = str_replace('/', $depr, $bind);
            // 如果有模块/控制器绑定
            $url = $bind . ('.' != substr($bind, -1) ? $depr : '') . ltrim($url, $depr);
        }

        list($path, $var) = $this->rule->parseUrlPath($url);

        return $path;

//        // 解析模块
//        $module = array_shift($path);
//
//        if ($this->param['auto_search']) {
//            $controller = $this->autoFindController($module, $path);
//        } else {
//            // 解析控制器
//            $controller = !empty($path) ? array_shift($path) : null;
//        }
//
//        // 解析操作
//        $action = !empty($path) ? array_shift($path) : null;
//
//        // 解析额外参数
//        if ($path) {
//            if ($this->rule->getConfig('url_param_type')) {
//                $var += $path;
//            } else {
//                preg_replace_callback('/(\w+)\|([^\|]+)/', function ($match) use (&$var) {
//                    $var[$match[1]] = strip_tags($match[2]);
//                }, implode('|', $path));
//            }
//        }
//
//        $panDomain = Request::panDomain();
//
//        if ($panDomain && $key = array_search('*', $var)) {
//            // 泛域名赋值
//            $var[$key] = $panDomain;
//        }
//
//        // 设置当前请求的参数
//        Request::setRouteVars($var);
//
//        // 封装路由
//        $route = [$module, $controller, $action];
//
//        if ($this->hasDefinedRoute($route, $bind)) {
//            throw new HttpException(404, 'invalid request:' . str_replace('|', $depr, $url));
//        }
//
//        return $route;
    }
186018
protected function loadFromUrl($url)
    {
        $url = $this->overrideUrl($url);
        $this->log->debug("Load from url $url");
        $this->initCurl();
        curl_setopt($this->curl, CURLOPT_URL, $url);
        if (!$data = $this->getDataFromCurl()) {
            return false;
        }

        // fix encoding
        $data = iconv('ISO-8859-15', 'UTF-8', $data);

        // validate data through parser
        if (!$this->isDataValid($data)) {
            $this->addError($url, 'Data not valid according to parser');

            return false;
        }

        // save result to disk
        $this->saveToCache($data);

        return true;
    }
411176
public function capture($url)
    {
        $this->setUrl($url);

        $client = new Client();
        $response = $client->post($this->apiUrl, ['form_params' =>
            [
                'key'    => $this->key,
                'url'    => $url,
                'width'  => $this->width,
                'height' => $this->height
            ]
        ]);

        $responseJson =  $response->getBody();
        $responseArray = json_decode($responseJson);

        $this->response = $responseArray;

        return $this;
    }
1343214
private function verifyUrl($url)
    {
        if (strpos($url, static::$_URL_VAR_CHARACTER) !== false) {
            throw new InvalidUrl(array(get_class($this), $url));
        }
        return true;
    }
742301
private function getUrlOrigin($url)
    {
        return array(
            parse_url($url, PHP_URL_SCHEME),
            parse_url($url, PHP_URL_HOST),
            parse_url($url, PHP_URL_PORT),
        );
    }
568050
public static function urlToPath($url)
    {
        $baseUrl = Yii::$app->request->hostInfo;
        $parsedUrl = parse_url($url);
        if (isset($parsedUrl['host']) && !strpos($baseUrl, $parsedUrl['host'])) {
            return false;
        }
        if (!isset($parsedUrl['path'])) {
            return false;
        }
        $path = str_replace('/' . basename(Yii::$app->request->scriptFile), '', $parsedUrl['path']);
        $request = self::$_request ? self::$_request : (self::$_request = new Request());
        $request->setPathInfo($path);
        $rule = explode('/', Yii::$app->urlManager->parseRequest($request)[0]);

        if (count($rule) == 2) {
            array_unshift($rule, Yii::$app->id);
        }
        if (count($rule)!=3) {
            return false;
        }
        return array_combine(['module', 'controller', 'action'], $rule);
    }
996828
public function wechatURL($url = '') {
        $weixin = array('system', 'wechat');
        $string = trim($_SERVER['REQUEST_URI'], "/");
        #判断是否是微信链接-内部跳转链接
        if (strstr($string, md5('wechat') . "_wechat")) {
            $weixin[] = 'userAuthorization';
            #获取自定义数据 4910_wechat/type/get/callback/-1?code=
            #为了获取URL地址中间4910_wechat到？之间的数据为自定义参数
            $wechat = md5('wechat') . "_wechat";
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            parse_str($pieces[1], $array);
            foreach ($array as $key => $value) {
                $weixin[] = $key;
                $weixin[] = $value;
            }
            return $weixin;
        }
        #第三方-授权事件接收URL  md5("Wechat Third-party) . "_wechat"; //事件回调
        elseif (strstr($string, md5('Wechat Third-party callback') . "_wechat")) {
            #thirdPartiesMessages
            $weixin[] = 'thirdPartiesMessages';
            $pieces   = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        }
        #第三方-授权事件回调地址
        elseif (strstr($string, md5('Wechat authorization callback') . "_wechat")) {
            $weixin[] = 'thirdAuthorizeCallback';
            $wechat   = md5('Wechat Third-party callback') . "_wechat";
            #获取中间跳转地址
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        }
        #第三方-消息与事件接收URL
        elseif (strstr($string, md5('Wechat callback') . "_wechat")) {
            $weixin[] = 'thirdCallback';
            $wechat   = md5('Wechat callback') . "_wechat";
            #获取中间跳转地址
            $str    = strlen($wechat);
            $len    = strrpos($string, '?');
            $num    = $len - $str;
            $new    = trim(substr($string, $str, $num), '/');
            $weixin = array_merge($weixin, explode("/", $new));
            #格式化数据
            $pieces = explode("?", $string);
            if (isset($pieces[1]) && !empty($pieces[1])) {
                parse_str($pieces[1], $array);
                foreach ($array as $key => $value) {
                    $weixin[] = $key;
                    $weixin[] = $value;
                }
            }
            return $weixin;
        } else {
            return $url;
        }

    }
284267
function imageStatus($key, $url) {
        $request = curl_init();
        curl_setopt_array($request, $this->options);
        //$this->prepareJSONRequest(self::API_STATUS_ENDPOINT(), $request, array('key' => $key), 'post', array());
        curl_setopt($request, CURLOPT_URL, self::IMAGE_STATUS_ENDPOINT());
        curl_setopt($request, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($request, CURLOPT_HTTPHEADER, array());
        $params = array('key' => $key, 'url' => $url);
        curl_setopt($request, CURLOPT_POSTFIELDS, json_encode($params));
        return $this->sendRequest($request, 1);
    }