Hl.WebMain/Source/jsplug/jq.xheditor/demos/saveremoteimg.php

(开头部分) 4KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php
/*!
 * saveremoteimg demo for php
 * @requires xhEditor
 * 
 * @author Yanis.Wang<yanis.wang@gmail.com>
 * @site http://xheditor.com/
 * @licence LGPL(http://www.opensource.org/licenses/lgpl-license.php)
 * 
 * @Version: 0.9.2 (build 110712)
 * 
 * ע����������Ϊ��ʾ�ã�ֻʵ�������򵥵�Զ��ץͼ��ճ���ϴ�������Ҫ���ƴ˹��ܣ�����Ҫ���п������¹��ܣ�
 *		1����ͼƬ��չ����URL��ַץȡ
 *		2����������ͼƬתjpg��ʽ���Լ���ˮӡ�Ⱥ�������
 *		3���ϴ���¼�������ݿ��Թ����û��ϴ�ͼƬ
 */
header('Content-Type: text/html; charset=UTF-8');
$attachDir='upload';//�ϴ��ļ�����·������β��Ҫ��/
$dirType=1;//1:��������Ŀ¼ 2:���´���Ŀ¼ 3:����չ����Ŀ¼  ����ʹ�ð�����
$maxAttachSize=2097152;//�����ϴ���С��Ĭ����2M
$upExt="jpg,jpeg,gif,png";//�ϴ���չ��
ini_set('date.timezone','Asia/Shanghai');//ʱ��

//����Զ���ļ�
function saveRemoteImg($sUrl){
	global $upExt,$maxAttachSize;
	$reExt='('.str_replace(',','|',$upExt).')';
	if(substr($sUrl,0,10)=='data:image'){//base64������ͼƬ�����ܳ�����firefoxճ��������ijЩ��վ�ϣ�����googleͼƬ
		if(!preg_match('/^data:image\/'.$reExt.'/i',$sUrl,$sExt))return false;
		$sExt=$sExt[1];
		$imgContent=base64_decode(substr($sUrl,strpos($sUrl,'base64,')+7));
	}
	else{//urlͼƬ
		if(!preg_match('/\.'.$reExt.'$/i',$sUrl,$sExt))return false;
		$sExt=$sExt[1];
		$imgContent=getUrl($sUrl);
	}
	if(strlen($imgContent)>$maxAttachSize)return false;//�����������������
	$sLocalFile=getLocalPath($sExt);
	file_put_contents($sLocalFile,$imgContent);
	//����mime�Ƿ�ΪͼƬ����Ҫphp.ini�п���gd2��չ
	$fileinfo= @getimagesize($sLocalFile);
	if(!$fileinfo||!preg_match("/image\/".$reExt."/i",$fileinfo['mime'])){
		@unlink($sLocalFile);
		return false;
	}
	return $sLocalFile;
}
//ץURL����
function getUrl($sUrl,$jumpNums=0){
	$arrUrl = parse_url(trim($sUrl));
	if(!$arrUrl)return false;
	$host=$arrUrl['host'];
	$port=isset($arrUrl['port'])?$arrUrl['port']:80;
	$path=$arrUrl['path'].(isset($arrUrl['query'])?"?".$arrUrl['query']:"");
	$fp = @fsockopen($host,$port,$errno, $errstr, 30);
	if(!$fp)return false;
	$output="GET $path HTTP/1.0\r\nHost: $host\r\nReferer: $sUrl\r\nConnection: close\r\n\r\n";
	stream_set_timeout($fp, 60);
	@fputs($fp,$output);
后面还有 50 行代码,购买后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。