[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
[phpBB Debug] PHP Warning: in file [ROOT]/includes/crs/crs_misc_functions.php on line 37: mime_content_type(): Empty filename or path
Zen Cart 源代码 functions_bmz_io.php

Zen Cart 源代码 functions_bmz_io.php




下载文件

文件名: functions_bmz_io.php
文件类型: PHP文件
文件大小: 4.11 KiB
MD5: 8c2bea0db9573ef0b91b468d6cd6d7d5

functions_bmz_io.php - 关闭高亮
  1. <?php
  2. /**
  3.  * bmz_image_handler.php
  4.  * general filesystem access handling
  5.  *
  6.  * @author  Tim Kroeger <tim@breakmyzencart.com>
  7.  * @author Andreas Gohr <andi@splitbrain.org>
  8.  * @copyright Copyright 2005-2006 breakmyzencart.com
  9.  * @copyright Portions Copyright 2005 splitbrain.org
  10.  * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License V2.0
  11.  * @version $Id: functions_bmz_io.php,v 1.2 2006/04/11 22:00:55 tim Exp $
  12.  */
  13.  
  14.  
  15. /**
  16.  * Tries to lock a file
  17.  *
  18.  * Locking uses directories inside $bmzConf['lockdir']
  19.  *
  20.  * It waits maximal 3 seconds for the lock, after this time
  21.  * the lock is assumed to be stale and the function goes on
  22.  *
  23.  * @author Andreas Gohr <andi@splitbrain.org>
  24.  * @author Tim Kroeger <tim@breakmyzencart.com>
  25.  */
  26. function io_lock($file){
  27.   global $bmzConf;
  28.   // no locking if safemode hack
  29.   if ($bmzConf['safemodehack']) return;
  30.  
  31.   $lockDir = $bmzConf['lockdir'] . '/' . md5($file);
  32.  
  33.  
  34.   $timeStart = time();
  35.   do {
  36.     //waited longer than 3 seconds? -> stale lock
  37.     if ((time() - $timeStart) > 3) break;
  38.     $locked = @mkdir($lockDir);
  39.   } while ($locked === false);
  40. }
  41.  
  42. /**
  43.  * Unlocks a file
  44.  *
  45.  * @author Andreas Gohr <andi@splitbrain.org>
  46.  * @author Tim Kroeger <tim@breakmyzencart.com>
  47.  */
  48. function io_unlock($file){
  49.   global $bmzConf;
  50.  
  51.   // no locking if safemode hack
  52.   if($bmzConf['safemodehack']) return;
  53.  
  54.   $lockDir = $bmzConf['lockdir'] . '/' . md5($file);
  55.   @rmdir($lockDir);
  56. }
  57.  
  58. /**
  59.  * Returns the name of a cachefile from given data
  60.  *
  61.  * The needed directory is created by this function!
  62.  *
  63.  * @author Andreas Gohr <andi@splitbrain.org>
  64.  * @author Tim Kroeger <tim@breakmyzencart.com>
  65.  *
  66.  * @param string $data  This data is used to create a unique md5 name
  67.  * @param string $ext   This is appended to the filename if given
  68.  * @return string       The filename of the cachefile
  69.  */
  70. function getCacheName($data, $ext='') {
  71.   global $bmzConf;
  72.  
  73.   $md5  = md5($data);
  74.   $file = $bmzConf['cachedir'] . '/' . $md5{0} . '/' . $md5.$ext;
  75.   io_makeFileDir($file);
  76.   return $file;
  77. }
  78.  
  79. /**
  80.  * Create the directory needed for the given file
  81.  *
  82.  * @author  Andreas Gohr <andi@splitbrain.org>
  83.  * @author  Tim Kroeger <tim@breakmyzencart.com>
  84.  */
  85. function io_makeFileDir($file){
  86.   global $messageStack;
  87.   global $bmzConf;
  88.  
  89.   $dir = dirname($file);
  90.   $dmask = $bmzConf['dmask'];
  91.   umask($dmask);
  92.   if(!is_dir($dir)){
  93.     io_mkdir_p($dir) || $messageStack->add("Creating directory $dir failed", "error");
  94.   }
  95.   umask($bmzConf['umask']);
  96. }
  97.  
  98. /**
  99.  * Creates a directory hierachy.
  100.  *
  101.  * @link    http://www.php.net/manual/en/function.mkdir.php
  102.  * @author  <saint@corenova.com>
  103.  * @author  Andreas Gohr <andi@splitbrain.org>
  104.  * @author  Tim Kroeger <tim@breakmyzencart.com>
  105.  */
  106. function io_mkdir_p($target){
  107.   global $bmzConf;
  108.  
  109.   if (is_dir($target) || empty($target)) return 1; // best case check first
  110.   if (@file_exists($target) && !is_dir($target)) return 0;
  111.   //recursion
  112.   if (io_mkdir_p(substr($target, 0, strrpos($target, '/')))){
  113.     if($bmzConf['safemodehack']){
  114.       $dir = preg_replace('/^' . preg_quote(realpath($bmzConf['ftp']['root']), '/') . '/', '', $target);
  115.       return io_mkdir_ftp($dir);
  116.     }else{
  117.       return @mkdir($target, 0777); // crawl back up & create dir tree
  118.     }
  119.   }
  120.   return 0;
  121. }
  122.  
  123. /**
  124.  * Creates a directory using FTP
  125.  *
  126.  * This is used when the safemode workaround is enabled
  127.  *
  128.  * @author <andi@splitbrain.org>
  129.  */
  130. function io_mkdir_ftp($dir){
  131.   global $messageStack;
  132.   global $bmzConf;
  133.  
  134.   if(!function_exists('ftp_connect')){
  135.     $messageStack->add("FTP support not found - safemode workaround not usable", "error");
  136.     return false;
  137.   }
  138.  
  139.   $conn = @ftp_connect($bmzConf['ftp']['host'], $bmzConf['ftp']['port'], 10);
  140.   if(!$conn){
  141.     $messageStack->add("FTP connection failed", "error");
  142.     return false;
  143.   }
  144.  
  145.   if(!@ftp_login($conn, $bmzConf['ftp']['user'], $bmzConf['ftp']['pass'])){
  146.     $messageStack->add("FTP login failed", "error");
  147.     return false;
  148.   }
  149.  
  150.   //create directory
  151.   $ok = @ftp_mkdir($conn, $dir);
  152.   //set permissions (using the directory umask)
  153.   @ftp_site($conn, sprintf("CHMOD %04o %s", (0777 - $bmzConf['dmask']), $dir));
  154.  
  155.   @ftp_close($conn);
  156.   return $ok;
  157. }
  158.  


cron