Jürgen Paul
Jürgen Paul

Reputation: 15007

PHP - fopen: failed to open stream: Invalid argument

i have a constant DOCROOT which is equal to C:\wamp\www\playground\, and I see nothing wrong with my current code:

$url = 'http://0.tqn.com/f/lg/a148.png';
$filename = 'love.png';

    $ch = curl_init($url);
    $fp = fopen(DOCROOT.'img2/'.$filename, 'wb');
    curl_setopt($ch, CURLOPT_FILE, $fp);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    fclose($fp);

The error is: fopen(C:\wamp\www\playground\img2/499511971screen0.png ) [function.fopen]: failed to open stream: Invalid argument. Why is it so? I tried to see related questions and the answer was something about double quotes which i'm not using.

Upvotes: 1

Views: 5398

Answers (1)

tim
tim

Reputation: 2039

Try surrounding the path with realpath or something equivalent. It will transform all slashes to the ones your operating system understands (in your case, change the forward slash to a backslash).

Upvotes: 2

Related Questions