0

hi

i am sending request to a server using curl, the resonse of the request is zip file, i have to download it. but the data are show on the page on binarry format(junck character).

this is he code.

 $ch =curl_init();
 $headers=array("key: 2434jdfdf3433434"); 
 curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
 curl_setopt($ch, CURLOPT_URL,
'https://xyz.com/api/batches/1481307454804189100');
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPGET,true);
$output = curl_exec($ch);
curl_close($ch);

if (empty($output))
{
    print "Sorry, the output is empty<p>";
}
else
{
    echo $output;

}

if i put this code ** header("Content-type:application/zip");** on the first line, i get save option, but its downloading the php file.

regards
rajan

Edited by Dani: Formatting fixed

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by svilla
0

What are you asking? You are echoing the contents of a zip file so it will look like junk characters. You have to some how unzip the file either from the 'download' or via a php function.

Here is the PHP manual with all of the zip functions: http://php.net/manual/en/ref.zip.php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.