Note that there are some explanatory texts on larger screens.

plurals
  1. POZipping images referenced from xml generated by mysql query
    primarykey
    data
    text
    <p>OK, I'll try and make this as easy to follow as I can!</p> <p><strong>Background:</strong> 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.</p> <p><strong>Problem:</strong> 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.</p> <p>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).</p> <p>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:</p> <pre><code>//Photos bit... $destination = 'tmp/ebay'; $filename = 'ebay-photos'; //images array $row = array(); foreach ($result-&gt;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-&gt;images as $images); } </code></pre> <p>The XML bit works, and is:</p> <pre><code>while ($row = @mysql_fetch_assoc($result)){ // XML $node = $dom-&gt;createElement("ad"); $newnode = $parnode-&gt;appendChild($node); $newnode-&gt;setAttribute("vrm",$row['vrm']); $newnode-&gt;setAttribute("make",$row['make']); $newnode-&gt;setAttribute("model",$row['model']); $newnode-&gt;setAttribute("type",$row['type']); $newnode-&gt;setAttribute("consumerPrice",$row['consumerPrice']); $newnode-&gt;setAttribute("numPreviousOwners",$row['numPreviousOwners']); $newnode-&gt;setAttribute("transmission",$row['transmission']); $newnode-&gt;setAttribute("images",$row['images']); $newnode-&gt;setAttribute("numPreviousOwners",$row['numPreviousOwners']); $newnode-&gt;setAttribute("color",$row['color']); } $dom-&gt;save('tmp/ebay/ebay.xml'); echo $dom-&gt;saveXML(); </code></pre> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload