无法让 php 以正确的名称保存文件名
由于某种原因,当使用此代码时,它输出的文件只是称为“.jpg”。
<?
$title = $GET['title'];
$url = $GET['url'];
$ourFileName = $title.jpg;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$ch = curl_init ("http://www.address.com/url=$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("images/$ourFileName",'w');
fwrite($fp, $rawdata);
fclose($fp);
echo ("<img src=images/$ourFileName>");
?>
很确定它与声明 $ourFileName 有关,任何帮助将不胜感激。
For some reason, when using this code the file it outputs is just called ".jpg".
<?
$title = $GET['title'];
$url = $GET['url'];
$ourFileName = $title.jpg;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$ch = curl_init ("http://www.address.com/url=$url");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$rawdata=curl_exec ($ch);
curl_close ($ch);
$fp = fopen("images/$ourFileName",'w');
fwrite($fp, $rawdata);
fclose($fp);
echo ("<img src=images/$ourFileName>");
?>
Pretty sure it has to do with declaring $ourFileName, any help would be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
看起来应该是以下内容:
Looks like it should be the following:
当然应该是
看起来那里充满了安全问题! 该脚本会用攻击者选择的文件覆盖其有权访问的任何文件!
Surely should be
Looks like a world of security problems there though! A script that overwrites any file it has permissions to with a file of an attackers choosing!
您确定
$GET['title']
正确吗? 用于访问 GET 参数值的超全局变量是$_GET
,而不是$GET
。Are you sure
$GET['title']
is correct? The superglobal variable for accessing the GET parameter values is$_GET
, not$GET
.尝试这个
$ourFileName = $title . “.jpg”;
Try this
$ourFileName = $title . ".jpg";
看起来这行
应该是
只要您确定 $_GET['title']; 中有一个值就应该这样做。
Looks like this line
Should be
That should do it as long as you are sure there is a value in $_GET['title'];