0

PHPコードに問題があります。

フォルダー名what-c​​ounter このフォルダーには、次の php コードを含む counter.php という名前のファイルと、hitcount.txt ファイルが含まれています。

<?php

$filename = '../what-counter/hitcount.txt';
$handle = fopen($filename, 'r');
$hits = trim(fgets($handle)) + 1;
fclose($handle);

$handle = fopen($filename, 'w');
fwrite($handle, $hits);
fclose($handle);

// Uncomment the next line (remove //) to display the number of hits on your page.
echo $hits;

?>

次の php コードは、ヒットをエコーするフォルダーのファイルでもルート ディレクトリ ファイルで使用されます。

<?php include("../what-counter/counter.php"); ?>

問題 コードはフォルダー内のファイルでは機能しますが、ルート ディレクトリに直接あるファイルでは機能しません。例: index.php はルート ディレクトリにあります

このコードを使用すると、この警告が表示されます

<?php include("what-counter/counter.php"); ?>

Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 4

Warning: fgets(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 6

Warning: fopen(../what-counter/hitcount.txt) [function.fopen]: failed to open stream: No such file or directory in /home/what/public_html/what-counter/counter.php on line 8

Warning: fwrite(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 9

Warning: fclose(): supplied argument is not a valid stream resource in /home/what/public_html/what-counter/counter.php on line 10

そして、このコードを使用すると、この警告が表示されます

<?php include("../what-counter/counter.php"); ?>

Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31

Warning: include(../what-counter/counter.php) [function.include]: failed to open stream: No such file or directory in /home/what/public_html/include/footer.php on line 31

Warning: include() [function.include]: Failed opening '../what-counter/counter.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/what/public_html
/include/footer.php on line 31

$filename url に対して何ができ、<?php include("../what-counter/counter.php"); ?>それをルート ディレクトリとフォルダー内のファイルで動作させるにはどうすればよいですか?

4

2 に答える 2