I have researched here:http://php.net/manual/en/function.curl-setopt.php and have enabled cURL, verified it is working correctly.
What is the best way to perform a file download (application/msword) using cURL on localhost (before moving to a hosting plan)?
A somewhat similar question exists here: Download file Curl with url var
The path to the file is known as $path, however, the URL is dynamic and is populated with the id of the file.
Path is populated like this:
$path = "./uploads/{$_SESSION['email']}/";
$path = $path . basename( $_FILES['userfile']['name']);
Here is a look at the download link itself:
<a href='ppage.php?id={$row['uid']}'>Download</a>
I currently have the following, and cannot get any output or error messages:
$fp = fopen ($path, 'w');
$ch = curl_init();
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_exec($ch);
curl_close($ch);
fclose($fp);
The file is a .doc and I can open it manually from its location. Permissions of the dir, subdir and the file itself are temporarily 777. If you could point me in the right direction I’d greatly appreciate it. Thanks in advance.
If that is all of your code, then you are missing the part where you set a URL to download: