`
kirenenko04
  • 浏览: 145961 次
  • 性别: Icon_minigender_2
  • 来自: 上海
社区版块
存档分类
最新评论

Magento get remote image size by auth user and password

 
阅读更多
<?php
class Bysoft_Myimage_Helper_Data extends Mage_Core_Helper_Abstract
{
	function common_filesize($url) {
		$user='';
		$pass='';
		$parse = parse_url($url);
		$host = $parse['host'];
		if ($host == 'gogear.preprodbysoftchina.com') {
			$user='gogear';
			$pass='bysoft2014';
			return $this->remote_filesize($url, $user, $pass);
		} else {
			return  getimagesize($url);
		}	
	}
	function remote_filesize($url, $user, $pass) { 
		$ch = curl_init($url);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_USERPWD, "$user:$pass");
		$data = curl_exec($ch);
		curl_close($ch);
		$ext = pathinfo($url,PATHINFO_EXTENSION);
		$filename = BP.DS.'media'.DS.'remote_file'.DS.time().'.'.$ext;
		$fp = @fopen($filename, "w+");
		fwrite($fp, $data);
		fclose($fp);	
		$info = getimagesize($filename);
		@unlink($filename);
		return $info;
	}
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics