|
目前已经确认是这个原因:插件用了这个PHP 的 file_get_contents()
因为我用了一个dx2自动保存图片的插件
网上查到说可以换成这样<?php
$ctx = stream_context_create(array(
'http' => array(
'timeout' => 1 //设置一个超时时间,单位为秒
)
)
);
file_get_contents("http://hostloc.com/", 0, $ctx);
?>
但我不知道怎么换,有高手指点一下吗,试了几次都不行;要是有好用的dx2自动保存图片的插件共享下也行
插件源码如下
<?php
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
class
plugin_yxf_picdown {
}
class plugin_yxf_picdown_forum extends
plugin_yxf_picdown {
function post_picdown(){
global $_G;
@extract($_G['cache']['plugin']
['yxf_picdown']);
if(!$_POST) return '';
if(!in_array
($_G['groupid'],(array)unserialize($usegids))) return '';
if
(!in_array($_G['fid'],(array)unserialize($usefids))) return '';
if
(preg_match_all("/\[img[^\]]*\](.*)\[\/img\]/isU",$_G['gp_message'],$regs)){
@set_time_limit(0);
require_once libfile
('class/image');
$image = new image;
if($downway==3){
require_once
libfile('class/ftp');
$ftp = new discuz_ftp();
if(!($_G['setting']['ftp']['connid'] = $ftp-
>connect())) {
return
FALSE;
}
}
$watermarkstatus=unserialize($_G['setting']
['watermarkstatus']);
$expdomains=explode("\n",str_replace("\r","",$expdomains));
$expdomains[]=$_G['siteurl'];
foreach ($regs[1] as
$key=>$url){
$url=trim($url);
if(substr($url,0,7)!='http://') continue;
$isexp=0;
foreach ($expdomains
as $domain){
$domain=trim($domain);
if
($domain&&strpos($url,$domain)!==false){
$isexp=1;
break;
}
}
if($isexp){
continue;
}
$ym=date('Ym');
$d=date('d');
$his=date('His');
if($downway==1){//保存为文件
$dir="data/downpic/";
if(!is_dir($dir)) @mkdir($dir);
$dir.="{$ym}/";
if(!is_dir
($dir)) @mkdir($dir);
$dir.="{$d}/";
if(!is_dir($dir)) @mkdir($dir);
$target=$dir.md5($url).".jpg";
$attachsave=savefile($url,$target);
if($attachsave){
if($watermarkstatus['forum'] && empty($_G['forum']
['disablewatermark'])) {
$image->Watermark($target);
}
$_G['gp_message']=str_replace($url,$_G['siteurl'].$target,$_G
['gp_message']);
}
}
elseif
($downway==2||$downway==3){//保存为附件
$remote=0;
if
(!is_dir($_G['setting']['attachdir']."/forum/".$ym."/")) @mkdir($_G['setting']
['attachdir']."/forum/".$ym."/");
if
(!is_dir($_G['setting']['attachdir']."/forum/".$ym."/".$d."/")) @mkdir($_G
['setting']['attachdir']."/forum/".$ym."/".$d."/");
$attachmenturl=$ym."/".$d."/".$his.strtolower(random(16)).".jpg";
$target=$_G['setting']
['attachdir']."/forum/".$attachmenturl;
if($downway==3){
$attachmenturl=$ym."/".$d."/".$his.strtolower(random(16)).".jpg";
$target=$_G['setting']['ftp']
['attachurl'].'/forum/'.$attachmenturl;
$ftp->upload($url,'forum/'.$attachmenturl);
$remote=1;
$sizeinfo=@getimagesize($url);
$attachsave=$sizeinfo[0];
}else{
$attachsave=savefile($url,$target);
}
if($attachsave){
$width=$attachsave;
$filename=$key.'.jpg';
$filetype='application/octet-stream';
$filesize=filesize($target);
$isimage=1;
$thumb=0;
if(!$remote){
$thumb = $image->Thumb($target, '', $_G['setting']['thumbwidth'], $_G
['setting']['thumbheight'], $_G['setting']['thumbstatus'], $_G['setting']
['thumbsource']) ? 1 : 0;
if(!$_G['setting']['thumbsource']) {
$width = $image->imginfo['width'];
}
/*
if($watermarkstatus['forum'] &&
empty($_G['forum']['disablewatermark'])) {
$image->Watermark($target);
}
*/
}
/*
DB::query("INSERT INTO ".DB::table
("forum_attachment_unused")." ( `aid` , `width` , `dateline` , `filename` ,
`filetype` , `filesize` , `attachment` , `downloads` , `isimage` , `uid` , `thumb` ,
`remote` )
VALUES (NULL , '0', '0', '$width', '{$_G['timestamp']}', '0', '0',
'{$filename}', '{$filetype}', '{$filesize}', '{$attachmenturl}', '0', '{$isimage}',
'{$_G['uid']}', '{$thumb}', '{$remote}');");
*/
DB::query("INSERT INTO ".DB::table("forum_attachment")."
( `aid` , `tid` , `pid` , `uid` , `tableid` ,
`downloads` )
VALUES
(NULL , '0',
'0', '{$_G['uid']}', '127', '0');");
$aid=DB::insert_id();
DB::query("INSERT INTO ".DB::table("forum_attachment_unused")."
( `aid` , `uid` , `dateline` ,
`filename` , `filesize` , `attachment` , `remote` , `isimage` , `width` ,
`thumb` )
VALUES
('$aid', '{$_G['uid']}', '{$_G
['timestamp']}', '{$filename}','{$filesize}', '{$attachmenturl}', '{$remote}',
'{$isimage}', '{$width}', '{$thumb}');");
$_G['gp_attachnew'][$aid]=array();
$_G['gp_message']=str_replace_once($regs[0]
[$key],"[attachimg]{$aid}[/attachimg]",$_G['gp_message']);//因为当前DX不支
持多次引用附件
}
}
}
if
($downway==3){
$ftp->ftp_close();
}
}
//die();
}
}
function
xdfopen($url, $limit = 0, $post = '', $cookie = '', $bysocket = FALSE, $ip = '',
$timeout = 15, $block = TRUE) {
$return = '';
$matches =
parse_url($url);
$host = $matches['host'];
$path = $matches
['path'] ? $matches['path'].(isset($matches['query']) && $matches['query'] ?
'?'.$matches['query'] : '') : '/';
$port = !empty($matches['port']) ? $matches
['port'] : 80;
if($post) {
$out = "POST $path HTTP/1.0
\r\n";
$out .= "Accept: */*\r\n";
$out .=
"Accept-Language: zh-cn\r\n";
$out .= "Content-Type:
application/x-www-form-urlencoded\r\n";
$out .= "User-Agent:
$_SERVER[HTTP_USER_AGENT]\r\n";
$out .= "Host:
$host\r\n";
$out .= 'Content-Length: '.strlen($post)."\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cache-Control: no-
cache\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
$out .= $post;
} else {
$out = "GET $path HTTP/1.0\r\n";
$out .= "Accept: */*\r\n";
$out .= "Accept-
Language: zh-cn\r\n";
$out .= "User-Agent: $_SERVER
[HTTP_USER_AGENT]\r\n";
$out .= "Host: $host\r\n";
$out .= "Connection: Close\r\n";
$out .= "Cookie: $cookie\r\n\r\n";
}
$fp = @fsockopen(($ip ? $ip : $host), $port, $errno, $errstr,
$timeout);
if(!$fp) {
return '';
} else {
stream_set_blocking($fp, $block);
stream_set_timeout
($fp, $timeout);
@fwrite($fp, $out);
$status =
stream_get_meta_data($fp);
if(!$status['timed_out']) {
while (!feof($fp)) {
if(($header =
@fgets($fp)) && ($header == "\r\n" || $header == "\n")) {
break;
}
}
$stop = false;
while(!feof($fp) && !$stop) {
$data =
fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
$return .= $data;
if($limit) {
$limit -= strlen($data);
$stop = $limit <= 0;
}
}
}
@fclose
($fp);
return $return;
}
}
function savefile($src,$target){
if(file_exists($target)){
}
elseif
(@copy($src,$target)){
}elseif ($content=@file_get_contents($src)){
$fp=@fopen($target,"w");
@fwrite($fp,$content);
@fclose($fp);
}elseif ($content=@xdfopen($src)){
$fp=@fopen($target,"w");
@fwrite($fp,$content);
@fclose($fp);
}
$sizeinfo=@getimagesize
($target);
if(!$sizeinfo[0]||!$sizeinfo[2]){
@unlink($target);
return false;
}else{
return $sizeinfo[0];
}
return false;
}
function str_replace_once($needle, $replace, $haystack) {
$pos = strpos($haystack, $needle);
if ($pos === false) {
return $haystack;
}
return substr_replace($haystack, $replace,
$pos, strlen($needle));
}
?> |
|