警告:file_put_contents()需要至少2个参数 - 但我给2个参数

Hi I have the function below which grabs and saves screenshots. It works 50% of the time but it sometimes fails with the following message: Warning: file_put_contents() expects at least 2 parameters, 1 given

I have dumped out the 2 parameters and can see that they both exist but the error message suggests otherwise

its driving me mad and any help would be appreciated..

<?php

grab_screenshot('http://www.usa4ink.com', 480, 240,"myscreen.jpg")

function grab_screenshot($url, $w, $h,$filename)
{
    global $imgPath;
    $filename = make_filename($filename,"jpg");
    $url = urlencode($url);
    $url = "http://s.wordpress.com/mshots/v1/$url/?w=$w&h=$h";
    $url = str_replace("//","/",$url);
    $url = str_replace("http:/","http://",$url);
    $image = file_get_contents($url);

    if($image!='')
    {
        file_put_contents(str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename, $image));
    }
    return get_subDir($filename)."/".$filename;
}
?>
file_put_contents(str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename, $image));

Nope you dont. Look closer.

file_put_contents(str_replace(param, param, param, param))

This is your code just before the return:

file_put_contents(
    str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename, $image)
);

As you can see, you are giving 1 parameter

Check your parentheses:

file_put_contents(str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename, $image));

Should be:

file_put_contents(str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename),  $image);