2012-11-03 47 views
0

您好我有以下功能抓住和保存屏幕截图。 它的工作原理的50%的时间,但它有时会失败,以下消息: 警告:file_put_contents()预计至少2个参数,1给出警告:file_put_contents()期望至少2个参数 - 但我给2参数

我已倒出的2个参数,并可以看到,它们都存在,但错误信息提示,否则

其驾驶我疯了,任何帮助,将不胜感激..

<?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; 
} 
?> 
+0

你错过了第二个参数,你为'str_replace'传递了两个参数,而不是'file_put_contents' –

+0

@PragneshChauhan:传递了'4'参数到'str_replace'和'1'参数到'file_put_contents' –

回答

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

都能跟得上你不。仔细观察。

file_put_contents(str_replace(param, param, param, param)) 
+0

谢谢...我一直盯着它太久:D – AttikAttak

2

这是你的代码只是返回前:

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

正如你所看到的,你给1个参数

2

检查括号:

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

应:

file_put_contents(str_replace("//","/",$imgPath."/".get_subDir($filename)."/".$filename), $image); 
相关问题