建立img.php空白文件,把下面的代码放入保存。
以TWCMS为例
打开twcms/model/cms_content_model.class.php
找到$v['pic'] = $this->cfg['webdir'].(empty($v['pic']) ? .....
替换成$v['pic'] = $this->cfg['webdir'].(empty($v['pic']) ? 'images/img.php' : $v['pic']);
完成后,如何文章里没有缩略图,那么就会调用img.php,而判断img.php里面的参数。
<?php
/**********************************************
* Filename : img.php
* Author : freemouse
* Usage:
* <img src=img.php>
* <img src=img.php?folder=images2/>
***********************************************/
if($_GET['folder']){
$folder=$_GET['folder'];
}else{
$folder='/images/';
}
//存放图片文件的位置
$path = $_SERVER['DOCUMENT_ROOT']."/".$folder;
$files=array();
if ($handle=opendir("$path")) {
while(false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if(substr($file,-3)=='gif' || substr($file,-3)=='jpg') $files[count($files)] = $file;
}
}
}
closedir($handle);
$random=rand(0,count($files)-1);
if(substr($files[$random],-3)=='gif') header("Content-type: image/gif");
elseif(substr($files[$random],-3)=='jpg') header("Content-type: image/jpeg");
readfile("$path/$files[$random]");
?>
Thomas2 年前
发表在:SQL Server2008报错:值不能为空[S35]
Thomas2 年前
发表在:解决Composer Installing dependencies from lock file你这都看不清了
1114 年前
发表在:Cetnos7 新手安装ZABBIX4.0.5详解教程有人嘛
Tyreunorm2020-08-27 22:51
发表在:php5.6 连接SQL SERVER<a href=https://mega...
耗子2020-04-08 15:02
发表在:写给正在创业的自己看到了,想写点。可能我开过这网站了,以后...
Thomas2019-11-19 19:57
发表在:twcms您的IP地址已改变,为了安全考虑,请重新登录这个好
酷喵2016-08-03 15:22
发表在:我家侄女成长记前排支持啦!
五爷2015-12-01 03:26
发表在:关于centos中的相关查看命令@admin:呵呵
admin2015-12-01 01:49
发表在:关于centos中的相关查看命令非常不错