lightinthebox zencart 自动添加商品多图

来源:互联网 发布:linux apt命令详解 编辑:程序博客网 时间:2024/04/29 10:15

 

// lightinthebox 多图添加开始

require_once(DIR_FS_CATALOG . DIR_WS_FUNCTIONS . 'extra_functions/functions_bmz_io.php');
if ($products_image_array )
{
 

 if (count($products_image_array) > 0)
 {
     $data = array();
     for($i = count ( $fileArray )-1; $i >=0; $i --)
     {

         $setSubFolder = date('d')<16?'a':'b';
         $nameBase = date('Ym').'/'.$setSubFolder.'/'.time().$i;
         $data['ImgExtension'] = strtolower(substr( $_FILES[$fileArray[$i]]['name'], strrpos($_FILES[$fileArray[$i]]['name'], '.')));

     }
 }

 foreach ( $products_image_array as $products_image )
 {
  
  
  if ( $products_image )
  {
            $data = array();
   //echo $img_dir;
   $path = pathinfo( $products_image );
            $path['basename'] = strip_spec_basename( $path['basename']);
            $data['ImgExtension'] =  strip_spec_basename( $path[['extension']);

            $setSubFolder = date('d')<16?'a':'b';
            $nameBase = date('Ym').'/'.$setSubFolder.'/'.time();
           
            $destination_name_vold= DIR_FS_CATALOG_IMAGES . 'vold/'.$nameBase . $data['ImgExtension'];

            // download  the  original image
         $info = getremoteimage( $products_image, $destination_name_vold);
   //echo $path;
   
            /*

            //Normal images
           $destination_name = DIR_FS_CATALOG_IMAGES . 's/'.$nameBase . $data['ImgExtension'];
   //ECHO $path['basename']; //文件名
      io_makeFileDir($destination_name);
            if ( !copy($source_name, $destination_name) )
            {
                    $messageStack->add( TEXT_MSG_NOUPLOAD_LARGE, "error" );
            }else
            {
                    $messageStack->add( TEXT_MSG_UPLOAD_LARGE, "success" );         
            }     
           */

        //die("11");
  $data['originalFileName'] = 'vold/'.$nameBase . $data['ImgExtension'];
        $data['smallFileName'] = 's/'.$nameBase . $data['ImgExtension'];
        $data['mediumFileName'] = 'l/'.$nameBase . $data['ImgExtension'];
        //print_r($data['mediumFileName']);
        $data['largeFileName'] = 'v/'.$nameBase . $data['ImgExtension'];
        //print_r($data['largeFileName']);
        $destination_name_original = DIR_FS_CATALOG_IMAGES .$data['originalFileName'];
        $destination_name_small = DIR_FS_CATALOG_IMAGES .$data['smallFileName'];
        $destination_name_medium = DIR_FS_CATALOG_IMAGES .$data['mediumFileName'];
        $destination_name_large = DIR_FS_CATALOG_IMAGES .$data['largeFileName'];
        io_makeFileDir($destination_name_medium);
        io_makeFileDir($destination_name_large);
        io_makeFileDir($destination_name_original);
 
   

 


        //copy medium image

 


          if (!copy($destination_name_vold, $destination_name_medium)) {
          $messageStack->add('failed to copy '.$destination_name_medium.'...', "error" );
          }else{
          $messageStack->add('Successed to copy '.$destination_name_medium.'...', "success" );
          if ($data['ImgExtension'] == ".jpg" || $data['ImgExtension'] == ".jpeg")
            $im = @imagecreatefromjpeg ($destination_name_medium );
          if ($data['ImgExtension'] == ".gif")
            $im = @imagecreatefromgif ($destination_name_medium );
            var_dump($im);
          if ($data['ImgExtension'] == ".png")
            $im = @imagecreatefrompng ($destination_name_medium );
          list($width_orig, $height_orig) = getimagesize($destination_name_medium );
          $width = PRODUCT_MEDIUM_IMAGE_WIDTH;
          $height = PRODUCT_MEDIUM_IMAGE_HEIGHT;
          if ($width && ($width_orig < $height_orig)) {
              $width = ($height / $height_orig) * $width_orig;
          } else {
              $height = ($width / $width_orig) * $height_orig;
          }

          $im_s = imagecreatetruecolor(PRODUCT_MEDIUM_IMAGE_WIDTH,PRODUCT_MEDIUM_IMAGE_HEIGHT);
          $white = imagecolorallocate($im_s, 255, 255, 255);
          imagefill($im_s, 0, 0, $white);
          if ($width_orig <= $width){
            $wpos=(PRODUCT_MEDIUM_IMAGE_WIDTH - $width_orig)/2;
            $hpos=(PRODUCT_MEDIUM_IMAGE_HEIGHT - $height_orig)/2;
            imagecopy($im_s,$im,$wpos, $hpos, 0, 0,$width_orig,$height_orig );
          }else{
            $wpos=(PRODUCT_MEDIUM_IMAGE_WIDTH - $width)/2;
            $hpos=(PRODUCT_MEDIUM_IMAGE_HEIGHT - $height)/2;
            imagecopyresampled($im_s,$im,$wpos, $hpos, 0, 0,$width,$height,$width_orig,$height_orig );
          }

          //imagecopyresampled($im_s, $im, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig );
          imagejpeg ( $im_s, $destination_name_medium, 100 );
          imagedestroy ( $im );      
        }

 

  $products_image = $info ? $img_dir.$path['basename'] : "";
  }
  

  if ( !$products_image )
  {
   
   exit( "图片上传失败" );
   
  }
    
   
   
  }
 echo "添加多图成功<br>";

      $products_image_names[] = 's/'.$nameBase.$data['ImgExtension'];
}
$products_image=implode($products_image_names,',');
//lightinthebox多图添加结束