Php 为什么这段代码没有fwrite语句就可以工作?
我试图理解PHP中的curl/fopen。下面的函数工作得很好,但我希望在某个时候看到fwritePhp 为什么这段代码没有fwrite语句就可以工作?,php,curl,fopen,fwrite,Php,Curl,Fopen,Fwrite,我试图理解PHP中的curl/fopen。下面的函数工作得很好,但我希望在某个时候看到fwrite function cURLdownload($url, $file) { if( !cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions"; $ch = curl_init(); if($ch) { $fp = fopen($file, "w"); if($fp)
function cURLdownload($url, $file)
{
if( !cURLcheckBasicFunctions() ) return "UNAVAILABLE: cURL Basic Functions";
$ch = curl_init();
if($ch)
{
$fp = fopen($file, "w");
if($fp)
{
if( !curl_setopt($ch, CURLOPT_URL, $url) )
{
fclose($fp); // to match fopen()
curl_close($ch); // to match curl_init()
return "FAIL: curl_setopt(CURLOPT_URL)";
}
if( !curl_setopt($ch, CURLOPT_FILE, $fp) ) return "FAIL: curl_setopt(CURLOPT_FILE)";
if( !curl_setopt($ch, CURLOPT_HEADER, 0) ) return "FAIL: curl_setopt(CURLOPT_HEADER)";
if( !curl_exec($ch) ) return "FAIL: curl_exec()";
curl_close($ch);
fclose($fp);
return "SUCCESS: $file [$url]";
}
else return "FAIL: fopen()";
}
else return "FAIL: curl_init()";
}
if(!curl_setopt($ch,CURLOPT_FILE,$fp))返回“FAIL:curl_setopt(CURLOPT_FILE)”代码>
告诉库将输出写入文件。
因此,当您使用curl\u exec()时,文件会立即被写入。您可以将其保存下来!如果已经调用了curl\u setopt($ch,CURLOPT\u FILE,$fp)
有关更多信息,请参见此