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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.