如何在magento 1.7.0中从外部URL导入产品图像? [英] How to import products images from external url in magento 1.7.0?

查看:43
本文介绍了如何在magento 1.7.0中从外部URL导入产品图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从magento 1.7版本的外部源URL导入"media/import"目录中的某些产品图像.有人请帮助我!

I want to import some products images in 'media/import' directory from a external source url in magento 1.7 version. Someone please help me !

推荐答案

以下是示例

$image_location = getDownloadImage("product",$image_url);               
if ( file_exists($image_location) ) {
    $product->addImageToMediaGallery($image_location,array('thumbnail','small_image','image'),true,false);
}

    // Download Image
    public function  getDownloadImage($type,$file){
        $path = str_replace("index.php","",$_SERVER["SCRIPT_FILENAME"]);        
        $import_location = $path.'media/catalog/';
        if (!file_exists($import_location)){
            mkdir($import_location, 0755);
        }
        $import_location = $path.'media/catalog/'.$type.'/';
        if (!file_exists($import_location)){
            mkdir($import_location, 0755);
        }

        // todo check if last character has /

        $file_source = Mage::getStoreConfig('oscommerceimportconf/oscconfiguration/conf_imageurl',Mage::app()->getStore()).$file;
        $file_target = $import_location."/".basename($file);

        $file_path = "";
        if (($file != '') and (!file_exists($file_target))){
            $rh = fopen($file_source, 'rb');
            $wh = fopen($file_target, 'wb');
            if ($rh===false || $wh===false) {
                // error reading or opening file
                $file_path = "";
            }
            while (!feof($rh)) {
                if (fwrite($wh, fread($rh, 1024)) === FALSE) {
                    $file_path = $file_target;
                }
            }
            fclose($rh);
            fclose($wh);
        }
        if (file_exists($file_target)){
            if ($type == 'category'){
                $file_path = $file;
            }else{
                $file_path = $file_target;
            }           
        }

        return $file_path;
    }               }

这篇关于如何在magento 1.7.0中从外部URL导入产品图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆