2012-09-11 39 views
0

好的,我会尽量让它尽量简单!从mysql查询生成的xml中引用的图像压缩

背景:我正在创建一个XML feed,以便使用php从MySql数据库中显示汽车上的ebay motors pro。我已成功创建了包含所有相关详细信息的xml文件,这些文件也是我的测试服务器的ftp。

问题:每张照片以regnumber_1.jpg,regnumber_2.jpg的形式登录到数据库中;等等,并链接到每辆车。图像驻留在名为autotrader的文件夹中。

我无法将autotrader文件夹中的图像发布到zip文件的ebay文件夹中。我只想复制mysql查询中的照片(即不是整个文件夹)。

我怀疑这是因为我没有正确完成foreach循环,但希望有人能够指出我正确的方向吗?下面的代码:

//Photos bit... 
$destination = 'tmp/ebay'; 
$filename = 'ebay-photos'; 

//images array 
$row = array(); 
foreach ($result->images as $images) { 
$images = explode(',', $row['images']); 
foreach ($images as $image) { 
copy('uploads/used-cars/autotrader/' . $image, $destination . $image); 
$all_images[] = $image; 
} 
} 

exec('zip -g0 ' . $zip_filename . ' *.jpg *.jpeg'); 
foreach ($all_images as $image) { 
@unlink($destination.$image); 
} 
$zip_filename = $filename . '.zip'; 

while ($row = @mysql_fetch_assoc($result)){ 
$all_images->images as $images); 
} 

的XML位的作品,并且是:

while ($row = @mysql_fetch_assoc($result)){ 
// XML 
$node = $dom->createElement("ad"); 
$newnode = $parnode->appendChild($node); 
$newnode->setAttribute("vrm",$row['vrm']); 
$newnode->setAttribute("make",$row['make']); 
$newnode->setAttribute("model",$row['model']); 
$newnode->setAttribute("type",$row['type']); 
$newnode->setAttribute("consumerPrice",$row['consumerPrice']); 
$newnode->setAttribute("numPreviousOwners",$row['numPreviousOwners']); 
$newnode->setAttribute("transmission",$row['transmission']); 
$newnode->setAttribute("images",$row['images']); 
$newnode->setAttribute("numPreviousOwners",$row['numPreviousOwners']); 
$newnode->setAttribute("color",$row['color']); 
} 

$dom->save('tmp/ebay/ebay.xml'); 
echo $dom->saveXML(); 

提前感谢!

+0

压缩像JPEG一样的压缩图像是浪费时间;你很幸运能够减小10%的尺寸。除非它是事物的ebay方面的要求,否则我会建议对图像进行tar如果有的话。有了焦油,你仍然可以保存文件,但不会浪费时间来压缩它。 –

+0

嗨。作为ebay的要求,有多个图像可以放入zip文件中。 – LeeG

回答

2

我创建了一个单独的php文件来检索照片,然后ftp zip文件。

现在可以关闭了。