Hi all
First post here, but have been reading for quite a while.
I'm currently using the script below to automate download and extraction of tradedoubler feeds. Can anyone help with adding some code to this to dynamically add a link to my xsl file? I Believe the current method to apply styles is to use DOM, but I feel it would be much nicer to be able to add a style link at line 2 of the xml when it's downloaded. Any help would be apreciated.
<?php
set_time_limit(0); // allow unlimited execution time
print "Downloading product feeds ...";
function download($file_source, $file_target) {
$rh = fopen($file_source, 'rb');
$wh = fopen($file_target, 'wb');
if ($rh===false || $wh===false) {
// error reading or opening file
return true;
}
while (!feof($rh)) {
if (fwrite($wh, fread($rh, 1024)) ===FALSE) {
// 'Download error: Cannot write to file ('.$file_target.')';
return true;
}
}
fclose($rh);
fclose($wh);
// test to see if $file_target is zipped
$filePointer = fopen($file_target,"r");
$fileHeader = fread($filePointer,4);
fclose($filePointer);
if ($fileHeader == "PK".chr(0x03).chr(0x04))
{
// try and unzip using unzip
$command = "/usr/bin/unzip -p ".$file_target." > ".$file_target.".unzipped";
exec($command);
if (filesize($file_target.".unzipped"))
{
unlink($file_target);
rename($file_target.".unzipped",$file_target);
}
}
else
{
// see if the file is gzipped (i.e. tradedoubler)
// however this cannot be detected from the header
// so you just have to try....!
$command = "/usr/bin/gzip -c -d -S \"\" ".$file_target." > ".$file_target.".ungzipped";
exec($command);
if (filesize($file_target.".ungzipped"))
{
unlink($file_target);
rename($file_target.".ungzipped",$file_target);
}
else
{
unlink($file_target.".ungzipped");
}
}
// No error
return false;
}
//Trade Doubler Feeds
download(
'http://...''test.xml);
print " done.";
?>