Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

Faker Image #1281

Closed
lagunawebdesign opened this issue Aug 28, 2017 · 4 comments
Closed

Faker Image #1281

lagunawebdesign opened this issue Aug 28, 2017 · 4 comments

Comments

@lagunawebdesign
Copy link

lagunawebdesign commented Aug 28, 2017

Could You remove curl() condition in Provider/Image.php - just $success = copy($url, $filepath); works great.
In curl condition there is a problem with unlink() function before fclose().

  /*
        // save file
        if (function_exists('curl_exec')) {
            // use cURL
            $fp = fopen($filepath, 'w');
            $ch = curl_init($url);
            curl_setopt($ch, CURLOPT_FILE, $fp);
            $success = curl_exec($ch) && curl_getinfo($ch, CURLINFO_HTTP_CODE) === 200;

            if ($success) {
                fclose($fp);
            } else {
                unlink($filepath);
            }

            curl_close($ch);
        } elseif (ini_get('allow_url_fopen')) {
            // use remote fopen() via copy()
            $success = copy($url, $filepath);
        } else {
            return new \RuntimeException('The image formatter downloads an image from a remote HTTP server. Therefore, it requires that PHP can request remote hosts, either via cURL or fopen()');
        }
        */
        $success = copy($url, $filepath);`
@fzaninotto
Copy link
Owner

there is a problem with unlink() function before fclose()

Can you be more specific?

@diegoldev
Copy link

diegoldev commented Oct 2, 2017

In my experience, I was getting this error when I used image() method, working in localhost (using WAMP)
Message: unlink(D:/path/to/facker/img/**e496355.jpg): Permission denied
I've solved it adding this lines before CURLOPT_FILE:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FILE, $fp);

@eberkund
Copy link
Contributor

eberkund commented Oct 11, 2017

@fzaninotto I can confirm the issue with unlink() and fclose(). I submitted a pull request that resolves it: #1319

@fzaninotto
Copy link
Owner

Fixed in #1319

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants