1

After two days of struggling my last hopes are on you. I'm trying to download a large (+/- 160 mb) XML-file from the Zanox servers. The download link to this file is dynamic and does not directly point to the file itself. I'm trying to download this file to my own server to parse it, but it's not working out for me. I've been using curl with the CURLOPT_HEADER set to 0. Can you guys help me out maybe?

Regards.

One of the codes I used:

$fp = fopen("productfeed1.xml", 'w+');
$c = curl_init($url);
curl_setopt($c, CURLOPT_FILE, $fp);  
curl_setopt($c, CURLOPT_HEADER, 0);
curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);  
$contents = curl_exec($c);
$info = curl_getinfo($c);
fwrite($fp, $contents);
curl_close($c); 
fclose($fp);
12
  • We cannot help of you do not post your code so far, explain what exactly the issue is and allow us to help you.
    – arkascha
    Commented Apr 27, 2014 at 10:49
  • I added one of the codes I have used, the issue is that I'm trying to download a file from a dynamic url, but the standard approach doesn't work.
    – Max
    Commented Apr 27, 2014 at 10:56
  • "doesn't work" is not a helpful description. What does that mean? What happens if you do it? Nothing happens? Do you get some error or some unexpected result? Does the universe implode?
    – arkascha
    Commented Apr 27, 2014 at 11:00
  • A wild guess, since you don't say what result you get: maybe you are missing the curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); flag?
    – arkascha
    Commented Apr 27, 2014 at 11:02
  • I'm sorry, I don't get an error, I just get a blank page. @arkascha; still no response with that flag added.
    – Max
    Commented Apr 27, 2014 at 11:06

1 Answer 1

1

Give this a try. (It works for me)

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:2.0.1) Gecko/20100101 Firefox/4.0.1");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt($ch, CURLOPT_MAXREDIRS, 10 );
curl_setopt($ch, CURLOPT_TIMEOUT, 36000);
curl_exec($ch);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.