特定のファイルが存在するかどうかを確認するphpスクリプトがあります。このファイル名は、「コンパートメント」変数によって定義されます。スクリプトをコピーして別のブロックに再度貼り付けると、コンパートメント変数のみを変更すると問題が発生します...
たとえば、1.jpegは存在しますが、2.jpegは存在しません。最初のブロックにはこのファイルへのリンクが表示されますが、2.jpegが存在しないため、アップロードフォームを表示する必要がある場合は2番目のブロックにも表示されます。
これは、$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. */
";
}
?>
ありがとうございました。