optikalefx Posted August 26, 2010 Share Posted August 26, 2010 Is this possible? I have a PHP file that serves a file (which is below the web root). That works fine and the download dialog is presented when directly accessed. Im building and API however, and that file needs to be served via HTTP Request. Im trying to get it working with cURL but right now its just outputting the raw byte data to the screen. Anyone had success or know what I need to try to be able to call that PHP file with cURL and have the browser try to download the file? (i've tried a lot of combinations of settings for this) $ch = curl_init(); curl_setopt($ch, CURLOPT_HEADER, 1); curl_setopt($ch, CURLOPT_URL,$remote); curl_setopt($ch,CURLOPT_BINARYTRANSFER,1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp); return curl_exec($ch); // side note I'm hoping the cURL settings don't matter too too much because a C# program will need to request the download. Link to comment https://forums.phpfreaks.com/topic/211836-php-serve-a-file-with-curl/ Share on other sites More sharing options...
btherl Posted August 26, 2010 Share Posted August 26, 2010 Sounds like you need to change the HTTP headers. Here's what microsoft says about it: http://support.microsoft.com/kb/260519 Link to comment https://forums.phpfreaks.com/topic/211836-php-serve-a-file-with-curl/#findComment-1104188 Share on other sites More sharing options...
optikalefx Posted August 27, 2010 Author Share Posted August 27, 2010 well the headers work well on their own, just not when curl is involved. Is there a way to carry the headers through curl? I know there is a CURLOPT_HEADER that when true it just prints the headers to screen. :/ Link to comment https://forums.phpfreaks.com/topic/211836-php-serve-a-file-with-curl/#findComment-1104331 Share on other sites More sharing options...
btherl Posted August 31, 2010 Share Posted August 31, 2010 You'll need to set the headers yourself if you are fetching a file with curl and then displaying it yourself. Rather than copying the original headers I would just set the ones you need using header(). Link to comment https://forums.phpfreaks.com/topic/211836-php-serve-a-file-with-curl/#findComment-1105472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.