【问题标题】:Zipping images referenced from xml generated by mysql query压缩从 mysql 查询生成的 xml 引用的图像
【发布时间】:2012-09-11 15:48:23
【问题描述】:

好的,我会尽量让这个过程变得简单易懂!

背景:我正在创建一个 XML 提要,以使用 php 从 MySql 数据库中显示 ebay motor 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();

提前致谢!

【问题讨论】:

  • 压缩像 jpeg 这样的压缩图像是浪费时间;你会很幸运能缩小 10% 的尺寸。除非这是 ebay 方面的要求,否则我建议将图像涂上焦油。使用 tar,您仍然只是存档,但不会浪费时间尝试压缩它。
  • 嗨。作为 ebay 的要求,有多个图像可以放入 zip 文件中。

标签: php mysql xml


【解决方案1】:

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

现在可以关闭了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多