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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.