问:随着谷歌Chrome,我可以很容易地检索与该URL的图像HTTP:/ /演示:demo@94.208.127.96:202 / snapshot.cgi或HTTP:/ /演示:demo@92.65.35.42:207 / snapshot.cgi
用命令“卷曲-u演示:演示HTTP:/ / 94.208.127.96:202/ snapshot.cgi > plaatje.jpg”形成一个Linux的计算机,我收到了图像的命令行。
现在,我想通过PHP脚本获取此图像,而不使用shell_exec或system命令。
我制作了下面的脚本,但是没有用。
谁可以帮助我进行这项工作?
PHP脚本
<?php
$ url =“ http:// 94.208.127.96/ snapshot.cgi ”;
$ port =“ 202”;
$ username =“ demo”;
$ password =“ demo”;
$ fh = fopen(“ / home / w4218398 / public_html / test / test.jpg”,“ w”)或die($ php_errormsg);
$ ch = curl_init();
回声“ username =”。$ username。“ <br>”;
回声“ password =”。$ password。“ <br>”;
回声“ url =”。$ url。“ <br> <br>”;
curl_setopt($ ch,CURLOPT_URL,$ url);
curl_setopt($ ch,CURLOPT_USERPWD,“ $ username:$ password”);
curl_setopt($ ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY);
curl_setopt($ ch,CURLOPT_PROTOCOLS,CURLPROTO_ALL);
curl_setopt($ ch,CURLOPT_PORT,$ port);
curl_setopt($ ch,CURLOPT_TIMEOUT,5);
curl_setopt($ ch,CURLOPT_FILE,$ fh);
$成功= curl_exec($ ch);
如果(!$ success)打印“ <br> <B>错误!</ b> <br>”;
$输出= curl_exec($ ch);
$ info = curl_getinfo($ ch);
curl_exec($ ch);
curl_close($ ch);
?>
相机1个网址:HTTP:/ / 94.208.127.96端口:202登录名:演示密码:demo 文件名:snapshot.cgi
相机2网址:HTTP:/ / 92.65.35.42端口:207登录名:演示密码:demo 文件名:snapshot.cgi
答:两件事情:
第一:检查权限。如果它在Web服务器上运行,请记住,Apache通常不会以您所使用的同一用户身份运行。(apache:也许是apache?)
第二:仅在网页外部进行测试...尝试不设置端口并执行以下操作:
$ url =“ http:// // 94.208.127.96:202/ snapshot.cgi ”;
我怀疑由于未在URL中定义端口,curl会忽略CURLOPT_PORT并由于指定了URL而默认为80。(假定您将在URL中包含端口信息)