holy shit

寺夺喜从天降

zencart 产品图片分析

数据库存放格式

数据表中只保留一个字段存储图片信息,保存从根目录下images目录为起点的路径名(不包含images),如a.jpg,a/b.jpg,以下称为原图。

中图和大图存放位置及命名格式

中图与大图分别位于images/medium和images/large,图片名为原图片名加中图后缀或大图后缀,如a_mid.jpg,a_lag.jpg

附加图片存放位置及命名格式

附加图片跟原图片相同目录,原图如果在images目录下,则附加图片命名格式为原图名加任意字符(后缀必须一样),原图如果在images下的子目录下,则附加图片命名格式为原图名加下划线加任意字符,同样,后缀名必须一样。
附加图中图大图位于images/medium和images/large下,目录结枸必须和原图一样,命名格式为附加图名加中图后缀或大图后缀。

取出原图中图、大图路径

$products_image_extension = substr($products_image, strrpos($products_image, '.'));
$products_image_base = str_replace($products_image_extension, '', $products_image);
$products_image_medium = $products_image_base . IMAGE_SUFFIX_MEDIUM . $products_image_extension;
$products_image_large = $products_image_base . IMAGE_SUFFIX_LARGE . $products_image_extension;

if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
  
$products_image_medium = DIR_WS_IMAGES . $products_image;
else {
  
$products_image_medium = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
}

if (!file_exists(DIR_WS_IMAGES . 'large/' . $products_image_large)) {
  
if (!file_exists(DIR_WS_IMAGES . 'medium/' . $products_image_medium)) {
    
$products_image_large = DIR_WS_IMAGES . $products_image;
  } 
else {
    
$products_image_large = DIR_WS_IMAGES . 'medium/' . $products_image_medium;
  }
else {
  
$products_image_large = DIR_WS_IMAGES . 'large/' . $products_image_large;
}

取出附加图片及相应中图大图路径

$images_array = array();
if ($products_image != '') {
  
$products_image_extension = substr($products_image, strrpos($products_image, '.'));
  
$products_image_base = str_replace($products_image_extension, '', $products_image);

  
if (strrpos($products_image, '/')) {
    
$products_image_match = substr($products_image, strrpos($products_image, '/')+1);
    
$products_image_match = str_replace($products_image_extension, '', $products_image_match. '_';
    
$products_image_base = $products_image_match;
  }

  
$products_image_directory = str_replace($products_image, '', substr($products_image, strrpos($products_image, '/')));
  
if ($products_image_directory != '') {
    
$products_image_directory = DIR_WS_IMAGES . str_replace($products_image_directory, '', $products_image. "/";
  } 
else {
    
$products_image_directory = DIR_WS_IMAGES;
  }

  
if ($dir = @dir($products_image_directory)) {
    
while ($file = $dir->read()) {
      
if (!is_dir($products_image_directory . $file)) {
        
if (substr($file, strrpos($file, '.')) == $products_image_extension) {
          
if(preg_match("/" . $products_image_base . "/i", $file== 1) {
            
if ($file != $products_image) {
              
if ($products_image_base . str_replace($products_image_base, '', $file== $file) {
                
$images_array[] = $file;
              } 
else {

              }
            }
          }
        }
      }
    }
    
if (sizeof($images_array)) {
      
sort($images_array);
    }
    
$dir->close();
  }
}

$num_images = sizeof($images_array);
$output_addtional_image_list = array();

if ($num_images) {
  
for ($i=0, $n=$num_images$i<$n$i++) {
    
$file = $images_array[$i];
      
$products_image_medium = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'medium/', $products_image_directory. str_replace($products_image_extension, '', $file. IMAGE_SUFFIX_MEDIUM . $products_image_extension;
    
if(file_exists($products_image_medium)){
        
$products_image_medium = $products_image_medium;
    }
else{
        
$products_image_medium = $products_image_directory . $file;
    }    
    
$products_image_large = str_replace(DIR_WS_IMAGES, DIR_WS_IMAGES . 'large/', $products_image_directory. str_replace($products_image_extension, '', $file. IMAGE_SUFFIX_LARGE . $products_image_extension;
    
if(file_exists($products_image_large)){
        
$products_image_large = $products_image_large;
    }
else{
        
$products_image_large = $products_image_directory . $file;
    }
    
$output_addtional_image_list[$i]['base_image'= $products_image_directory . $file;
    
$output_addtional_image_list[$i]['medium_image'= $products_image_large;
    
$output_addtional_image_list[$i]['large_image'= $products_image_large;
  }
}
posted @ 2011-04-30 15:05  潜水鱼  阅读(1747)  评论(0编辑  收藏  举报

holy shit on foot