Due to hosting company restrictions we cannot use fopen() or file_put_contents(). So the question is, can I substitute the following code with cURL?
$fp = fopen("xyz/abc.pdf", "w");
if($fp)
{
fwrite($fp, $contents);
fclose($fp);
}
Additionally, the directory to which we are writing the file is outside of the web root (for security purposes).
Maybe help:
function curl_download($Url, $saveTo)
{
$fp = fopen ($saveTo, 'w+');
$ch = curl_init($Url);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 1000);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
$result = curl_close($ch);
return $result;
}
curl_download('http://code.freetuts.net/upload/tut/images/2015/03/25/345/selector-la-gi-tim-hieu-css-selector-can-ban.gif', './');