Jump to content

PHP serve a file with cURL


optikalefx

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.