2, the content of the .htaccess file:
-
-
- RewriteEngine On
-
- # '-s' (is regular file, with size)
- # '-l' (is symbolic link)
- # '-d' (is directory)
- # 'ornext|OR' (or next condition)
- # 'nocase|NC' (no case)
- # 'last|L' (last rule)
-
- RewriteCond %{REQUEST_FILENAME} -s [OR]
- RewriteCond %{REQUEST_FILENAME} -l [OR]
- RewriteCond %{REQUEST_FILENAME} -d
- RewriteRule ^.*$ - [NC,L]
- RewriteRule ^.*$ createthumb.php?path=%{REQUEST_URI} [NC,L]
-
-
Copy code
For the configuration method of htaccess file, please refer to:
Detailed explanation of apache .htaccess configuration
.htaccess configuration detailed explanation (a comprehensive classic not to be missed)
.htaccess file usage summary
.htaccess tutorial.htaccess learning summary
Example of Apache using .htaccess to configure pseudo-static configuration
A few examples of htaccess pseudo-static rule configuration
Discuss: htaccess URL rewrite and redirect redirect
3. createthumb.php
-
- define('WWW_PATH', dirname(dirname(__FILE__))); // Site www directory
-
- require(WWW_PATH.'/PicThumb.class.php'); // include PicThumb.class.php
- require(WWW_PATH.'/ThumbConfig.php'); // include ThumbConfig.php
-
- $logfile = WWW_PATH.'/createthumb.log'; // Log file
- $source_path = WWW_PATH.'/ upload/'; // Original path
- $dest_path = WWW_PATH.'/supload/'; // Target path
-
- $path = isset($_GET['path'])? $_GET['path'] : '' ; // Accessed image URL
-
- // Check path
- if(!$path){
- exit();
- }
-
- // Get image URI
- $relative_url = str_replace($dest_path, '', WWW_PATH.$ path);
-
- // Get type
- $type = substr($relative_url, 0, strpos($relative_url, '/'));
-
- // Get config
- $config = isset($thumb_config[$type]) ? $thumb_config[$type] : '';
-
- // Check config
- if(!$config || !isset($config['fromdir'])){
- exit();
- }
-
- // Original Image file
- $source = str_replace('/'.$type.'/', '/'.$config['fromdir'].'/', $source_path.$relative_url);
-
- // Target file
- $ dest = $dest_path.$relative_url;
-
- // Create thumbnail
- $obj = new PicThumb($logfile);
- $obj->set_config($config);
- if($obj->create_thumb($source , $dest)){
- ob_clean();
- header('content-type:'.mime_content_type($dest));
- exit(file_get_contents($dest));
- }
-
- ?>
Copy code
4,ThumbConfig.php
-
- $thumb_config = array(
-
- 'news' => array(
- 'fromdir' => 'news', // Source directory
- 'type' => 'fit ',
- 'width' => 100,
- 'height' => 100,
- 'bgcolor' => '#FF0000'
- ),
-
- 'news_1' => array(
- 'fromdir' => ; 'news',
- 'type' => 'fit',
- 'width' => 200,
- 'height' => 200,
- 'bgcolor' => '#FFFF00'
- ),
-
- 'article' => array(
- 'fromdir' => 'article',
- 'type' => 'crop',
- 'width' => 250,
- 'height' => 250,
- ' watermark' => WWW_PATH.'/supload/watermark.png'
- )
-
- );
-
- ?>
Copy code
For example, after accessing these three paths, thumbnails will be automatically generated by pressing config
http://localhost/supload/news/2013/07/21/1.jpg
http://localhost/supload/news_1/2013/07/21/1.jpg
http://localhost/supload/article/2013/07/21/2.jpg
Attachment, php automatically generates the source code download address of the thumbnail according to the url
|