我有一个 php 脚本,用于检查特定文件是否存在。该文件的名称由“compartment”变量定义。当脚本被复制并再次粘贴到单独的块中时,仅更改隔间变量就会遇到问题......
例如说 1.jpeg 存在,但 2.jpeg 不存在。第一个块显示指向该文件的链接,但是当它应该显示上传表单时,第二个块也是如此,因为 2.jpeg 不存在。
就好像 $currentfile 或 $filename 变量被转移到它们下面的块中。
请在下面找到我的问题的示例...
<?php
$compartment = "1";
foreach (glob("$compartment.*") as $filename) {
$currentfile = "$filename";
}
if (file_exists($currentfile)) {
echo "
/* If the file exists, it will display a link to the file. */
<a href='$currentfile' target='_blank'>LAUNCH PREVIEW</a>
";
} else {
echo "
/* Here is an uploader form that would transform foobar.jpeg into $compartment.jpeg. */
";
}
?>
<?php
$compartment = "2";
foreach (glob("$compartment.*") as $filename) {
$currentfile = "$filename";
}
if (file_exists($currentfile)) {
echo "
/* If the file exists, it will display a link to the file. */
<a href='$currentfile' target='_blank'>LAUNCH PREVIEW</a>
";
} else {
echo "
/* Here is an uploader form that would transform foobar.jpeg into $compartment.jpeg. */
";
}
?>
谢谢你。