OK, I’ll try and make this as easy to follow as I can!
Background: I’m creating an XML feed to display cars on ebay motors pro from a MySql database using php. I have successfully created the xml file with all the relevant details, which also ftp’s to my test server.
Problem: Each car photo is logged in the database as regnumber_1.jpg, regnumber_2.jpg; and so on, and linked to each vehicle. The images reside in a folder called autotrader.
I’m having trouble posting the images from the autotrader folder into the ebay folder within a zip file. I only want to copy the photos from the mysql query (i.e. not the entire folder).
I suspect it’s because I haven’t done the foreach loop correctly, but hopefully someone will be able to point me in the right direction? Here’s the code:
//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);
}
The XML bit works, and is:
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();
Thanks in advance!
I’ve created a separate php file to retrieve the photos and then ftp the zip file.
This can now be closed.