警告:取消链接(/web/htdocs/www.vhannibal.net/home/setting/):是 [...]
require("$_SERVER[DOCUMENT_ROOT]mysql.php");
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM Setting WHERE ID = \"$id\"");
$row = mysql_fetch_array($result);
switch ($_GET["action"])
{
case "update":
if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]"))
{
echo "Non è stato possibile cancellare il vecchio file.";
header("Refresh: 2.5; url=index.php");
exit();
}
错误是“警告:取消链接(/web/htdocs/www.vhannibal.net/home/setting/):第43行是[...]中的目录”,第43行是
if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]"))
有什么问题吗?
require("$_SERVER[DOCUMENT_ROOT]mysql.php");
$id = $_GET["id"];
$result = mysql_query("SELECT * FROM Setting WHERE ID = \"$id\"");
$row = mysql_fetch_array($result);
switch ($_GET["action"])
{
case "update":
if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]"))
{
echo "Non è stato possibile cancellare il vecchio file.";
header("Refresh: 2.5; url=index.php");
exit();
}
The error is "Warning: unlink(/web/htdocs/www.vhannibal.net/home/setting/): Is a directory in [...] on line 43", line 43 is
if (!unlink("$_SERVER[DOCUMENT_ROOT]setting/$row[Filename]"))
What's wrong with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您应该考虑回到基础知识并阅读输入验证。
忽略明显的 mysql 注入问题,
unlink()
只能在文件上调用。在此处的代码中,在删除$row['Filename']
之前,您不会检查它是否是一个文件。您至少可以检查该文件是否存在
First off, you should consider going back to basics and reading up on input validation.
Ignoring the glaring mysql injection issue,
unlink()
can only be called on files. In your code here, you don't check whether$row['Filename']
is a file or not before deleting it.The least you could do is check whether the file exists
$row[Filename] 中没有任何数据或其空字符串。
$row[Filename] is not having any data in it or its empty string.
由于还没有正确答案,我必须自己写。
正如 Gaurav 指出的那样,您没有检查 mysql 查询是否返回任何数据
因此,您的代码应该是(但是,我会以更常用的方式编写字符串):
As there is still no right answer I have to write it myself.
As Gaurav pointed it out, you are not checking if mysql query returned any data
thus, your code should be (however, I'd write strings more usual way):