步骤一
在根目录的api文件夹内建立一个pic.php文件,放入下面的代码:
伪静态设置:
- <?php
- defined('IN_PHPCMS') or exit('No permission resources.');
- if(isset($_SERVER['HTTP_REFERER'])){
- if(strpos($_SERVER['HTTP_REFERER'],APP_PATH)==0){
- pic();
- }
- else{
- echo "Welcome to Picture Generation library system";
- }
- }
- elseif(checkrobot()){
- pic();
- }else{
- echo "Welcome to Picture Generation library system";
- }
- //判断是不是蜘蛛
- function checkrobot($useragent=''){
- static $kw_spiders = array('bot', 'crawl', 'spider' ,'slurp', 'sohu-search', 'lycos', 'robozilla');
- static $kw_browsers = array('msie', 'netscape', 'opera', 'konqueror', 'mozilla');
- $useragent = strtolower(empty($useragent) ? $_SERVER['HTTP_USER_AGENT'] : $useragent);
- if(strpos($useragent, 'http') === false && dstrpos($useragent, $kw_browsers)) return false;
- if(dstrpos($useragent, $kw_spiders)) return true;
- return false;
- }
- function dstrpos($string, $arr, $returnvalue = false) {
- if(empty($string)) return false;
- foreach((array)$arr as $v) {
- if(strpos($string, $v) !== false) {
- $return = $returnvalue ? $v : true;
- return $return;
- }
- }
- return false;
- }
- ?>
- Apache伪静态:
- RewriteRule ^pic\/([0-9]+)-([0-9]+)\.png$ api.php?op=pic&catid=$1&id=$2
- Nginx伪静态:
- rewrite ^(.*)/pic/([0-9]+)-([0-9]+).png$ $1/api.php?op=pic&catid=$2&id=$3 last;
内容页模板调用代码:
- <img src="/pic/{$title}.jpg"/>
【转自csdn:https://blog.csdn.net/cnpinpai/article/details/125711980】
文章点评