0
votes

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!

2
failed to open stream: No such file or directory OR failed to open stream: Permission denied?Vickel

2 Answers

1
votes

every thing is correct. just grant permission of directory

C:\xampp\htdocs\scraper\application\temp

as you can see permission is denied. so no one else accept admin are able to made changes to specific directory.

0
votes

try this for blob type:

if (count($_FILES) > 0) {
    if (is_uploaded_file($_FILES['image']['tmp_name'])) {
       $imgData = addslashes(file_get_contents($_FILES['image']['tmp_name']));
        $imageProperties = getimageSize($_FILES['image']['tmp_name']);

        }