无法让 php 以正确的名称保存文件名

发布于 2024-07-25 05:17:50 字数 636 浏览 2 评论 0原文

由于某种原因,当使用此代码时,它输出的文件只是称为“.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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

茶色山野 2024-08-01 05:17:51

看起来应该是以下内容:

$ourFileName = $title.'.jpg';

Looks like it should be the following:

$ourFileName = $title.'.jpg';
痴情换悲伤 2024-08-01 05:17:51

当然应该是

$title = $_GET['title'];
$url = $_GET['url'];
$ourFileName = $title.'.jpg';

看起来那里充满了安全问题! 该脚本会用攻击者选择的文件覆盖其有权访问的任何文件!

Surely should be

$title = $_GET['title'];
$url = $_GET['url'];
$ourFileName = $title.'.jpg';

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!

稍尽春風 2024-08-01 05:17:50

您确定 $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.

你的呼吸 2024-08-01 05:17:50

尝试这个
$ourFileName = $title . “.jpg”;

Try this
$ourFileName = $title . ".jpg";

酷遇一生 2024-08-01 05:17:50

看起来这行

$ourFileName = $title.jpg;

应该是

$ourFileName = $title . ".jpg";

只要您确定 $_GET['title']; 中有一个值就应该这样做。

Looks like this line

$ourFileName = $title.jpg;

Should be

$ourFileName = $title . ".jpg";

That should do it as long as you are sure there is a value in $_GET['title'];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文