Hi,
I tested the demo of the below datafeed on this site and it works on this site:
{link saved}
However, on my site I get a blank page but no errors when I add MagicParser_getErrorMessage(). I can also parse other files without a problem.
Any ideas?
Cheers,
Gareth
Brilliant, thanks. Yes, unzipped locally and works fine. I've already found a php class that should do the unzipping so should be good from here.
Thanks for the excellent support.
Hello Gareth,
The URL in your post is returning a PKZIPPED response, which is why it cannot be opened normally. PHP doesn't support PKZIP compression; however the demo script on this website uses a different method to download URLs which does check for compression.
If you download the link to your computer, unzip (using winzip for example); and then upload the uncompressed file to your server it would work correctly as a local file.
In order to parse this directly from PHP, you would need to look at an alternative way to retrieve the file that allows you to unzip the content.
If you want to try and simulate the way the Magic Parser demo script handles this file; you could try the following script, but it would require that your server has access the unzip program, and has permission to execute it using the exec() function.
This will download the file to a directory called files/ relative to the directory in which you run this script; so you will need to make this directory writable to PHP. The easiest way to do this is normally with your FTP program - make the directory; then in the remote window right-click and look for properties / permission, and then make the folder writable by all/world.
Have a go with this for starters, but if no joy let me know and we'll look at other ways of automating the unzip for you....
test.php
<?php
require("MagicParser.php");
$url = "http://free.3dtracking.net/live.kmz?guid=66d1dd3f-bc1c-40cf-acfc-7dfccc351e62";
$filename = "files/live.kmz";
$input = fopen($url,"r");
$output = fopen($filename,"w");
if (!$input)
{
print "Could not open ".$url;exit();
}
if (!$output)
{
print "Could not create ".$filename." - check permissions!";exit();
}
while(!feof($input))
{
fwrite($output,fread($input,1024));
}
fclose($output);
fclose($input);
// now attempt to unzip
$cmd = "unzip -p ".$filename." > ".$filename.".unzipped";
exec($cmd);
rename($filename.".unzipped",$filename);
// finally parse the unzipped version
function myRecordHandler($record)
{
print_r($record);
}
MagicParser_parse($filename,"myRecordHandler","xml|KML/");
?>
(remember to create the directory "files" for PHP to download the zipped file to!)
Cheers,
David.