我不确定为什么这不起作用,有人可以帮忙吗?我想看看是否 $ lines [$ y] 与“../../ Files / Person / $ username / files / $ share_person_post”相同,但即使是,它也是没有运行代码。
if (file_exists("../../Files/Person/$username/shared.txt")) {
$lines = file("../../Files/Person/$username/shared.txt");
$size = sizeof($lines);
$size = $size - 1;
$shared_location = "Unknown";
for($y = 0; $y <= $size; $y++) {
echo $lines[$y];
if ($lines[$y] == "../../Files/Person/$username/files/$share_person_post") {
echo "Here";
$z = $y + 1;
$shared_location = $lines[$z];
$fmsg = "<p>This file is already shared at $shared_location</p>";
$ex = "0";
}
}
}
答案 0 :(得分:0)
尝试使用explode,我知道当我抓取文本文件时,它们都是一个长字符串。它可能是我的服务器或php版本,但值得一试。
if (file_exists("../../Files/Person/$username/shared.txt"))
{
$data = file("../../Files/Person/$username/shared.txt");
$lines = explode("\n",$data);
$size = count($lines);
$size = $size - 1;
$shared_location = "Unknown";
for($y = 0; $y <= $size; $y++)
{
echo $lines[$y];
if($lines[$y] == "../../Files/Person/$username/files/$share_person_post")
{
echo "Here";
$z = $y + 1;
$shared_location = $lines[$z];
$fmsg = "<p>This file is already shared at
$shared_location</p>";
$ex = "0";
}
}
}