I am trying to download an image from online and store it to my localhost but I receive the following:
A PHP Error was encountered Severity: Warning
Message: file_put_contents(C:\xampp\htdocs\scraper\application\temp): failed to open stream: Permission denied
Filename: controllers/Scrape.php
Line Number: 69
Backtrace:
File: C:\xampp\htdocs\scraper\application\controllers\Scrape.php Line: 69 Function: file_put_contents
File: C:\xampp\htdocs\scraper\index.php Line: 315 Function: require_once
public function DownloadImages(){
$img = 'http://daytodata.net/wp-content/uploads/2018/09/Dise%C3%B1o-sin-t%C3%ADtulo-35.png';
$dest = APPPATH."temp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $img);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);
if (empty($curl_err)) {
file_put_contents($dest, $result);
}
}
What I'm looking to do is save it to my localhost. Would it be better to store it as a blob in my mysql table instead of locally? Either way, any help with the above would be useful!