我正在使用从API导入产品的wordpress主题。它会拉动图像并将其设置为特色图像。 以下是获取图像的代码:
// Get the image
$post_image = (string)$item->{"image-url"};
以下是将图像设置为精选图片的代码:
// Update Featured image
if($post_image!= "")
imwb_zonpress_theme_products_set_featured_image($postId, $post_image);
在url具有如下图像扩展名的情况下,它可以正常工作:
http://media.stickyj.com/product/AX3026.jpg
问题出现在图片网址如下:
http://cdn.is.bluefly.com/mgen/Bluefly/prodImage.ms?productCode=336924201&width=340&height=408
问题是,如何从此网址中提取图片?
答案 0 :(得分:0)
这将起作用
$img_url = 'http://cdn.is.bluefly.com/mgen/Bluefly/prodImage.ms?productCode=336924201&width=340&height=408';
$save = 'filename.jpg';
file_put_contents($save, file_get_contents($img_url));
<强> 输出 强>
图像
答案 1 :(得分:0)
PHP有一个内置函数file_get_contents()
,它将文件内容读入字符串。
<?php
//Get the file
$content = file_get_contents("http://cdn.is.bluefly.com/mgen/Bluefly/prodImage.ms?productCode=336924201&width=340&height=408");
//Store in the filesystem. $fp = fopen("http://cdn.is.bluefly.com/mgen/Bluefly/prodImage.ms?productCode=336924201&width=340&height=408", "w");
fwrite($fp, $content); fclose($fp); ?>