我想尝试连接到远程文件并将输出从那里写入本地文件,这是我的功能:
原文链接:https://www.f2er.com/php/131892.htmlfunction get_remote_file_to_cache() { $the_site="http://facebook.com"; $curl = curl_init(); $fp = fopen("cache/temp_file.txt","w"); curl_setopt ($curl,CURLOPT_URL,$the_site); curl_setopt($curl,CURLOPT_FILE,$fp); curl_setopt($curl,CURLOPT_RETURNTRANSFER,TRUE); curl_exec ($curl); $httpCode = curl_getinfo($curl,CURLINFO_HTTP_CODE); if($httpCode == 404) { touch('cache/404_err.txt'); }else { touch('cache/'.rand(0,99999).'--all_good.txt'); } curl_close ($curl); }
它在“缓存”目录中创建两个文件,但问题是它不会将数据写入“temp_file.txt”,为什么?
谢谢!
[R