- 論壇徽章:
- 18
|
大家好!
我有一個問題向大家請教。
我的服務器在公司防火墻之內(nèi),需要通過http代理上網(wǎng),所以我在原來可以正常執(zhí)行的php程序中加了curl實現(xiàn)通過http代理上網(wǎng)的代碼。
但是發(fā)現(xiàn)并不能正常執(zhí)行。請大家?guī)臀铱纯村e在哪里呢?- <?php
- header("Content-Type: text/html; charset=UTF-8");
- date_default_timezone_set('PRC');
- $cweekday = array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");
- $now = getdate(time());
- $cur_wday=$now['wday'];
- $cur_mon=$now['mon'] - 1;
- $cntime = date("現(xiàn)在時刻:Y年n月j日$cweekday[$cur_wday],G點i分。");
- echo $cntime;
- $newfname = './tmp/now.wmv';
- $creqBaseURL = 'http://translate.google.cn/translate_tts?ie=UTF-8&q=' . $cntime . '&tl=zh-CN';
- //這里開始是新加的內(nèi)容。
- $ch = curl_init();
- $timeout = 5;
- curl_setopt($ch, CURLOPT_URL, $creqBaseURL);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
- curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
- curl_setopt($ch, CURLOPT_PROXY, "sg.proxy.alcatel-lucent.com");
- curl_setopt($ch, CURLOPT_PROXYPORT, 8000);
- curl_setopt($ch, CURLOPT_PROXYUSERPWD, "username:password");
- curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
- $file_contents = curl_exec($ch);
- //這里結束是新加的內(nèi)容
- $cremote_file = fopen($file_contents, "rb"); //原來這句是$cremote_file = fopen($creqBaseURL, "rb");
- $newf = fopen($newfname, "wb");
- if ($newf){
- while(!feof($cremote_file)){
- fwrite($newf, fread($cremote_file, 1024 * 8),1024 * 8);
- }
- fclose($newf);
- }
- fclose($cremote_file);
- curl_close($ch);
- echo '<embed loop="1" autostart="true" hidden="true" src=./tmp/now.wmv />';
- ?>
復制代碼 php報的錯是:[Mon Jul 20 14:42:48 2015] [error] [client 192.11.236.118] PHP Warning: fopen(): Filename cannot be empty in /var/www/html/1.php on line 34
為什么會出這個錯呢?
請指教。
謝謝大家! |
|