這是我的javascript函數。
<script>
function output($file_name, $content)
{
document.getElementById("content_title").innerHTML=" "+$file_name;
document.getElementById("content").innerHTML=" "+$content;
}
</script>
這是我的PHP代碼;
<?php
$dir = "img_png";
$files = scandir($dir);
$dir_length = count($files);
?>
這是我的PHP代碼的第二部分(有問題);問題:何時$ content =「任何字符串」;一切正常,但當$ content = file_get_contents('file');我的觸發函數根本不會改變任何.innerHTML元素。
<?php
for ($i=2;$i<$dir_length;$i++){
$title=explode(".png", $files[$i]);
$content=file_get_contents('./content_txt/tv.txt');
echo "<td><button id='button' class='button' onClick=\"output('", $title[0],"";
echo "', '", $content,"";
echo "')\"><img src=\"/img_png/", $files[$i], "\"></img></button></td>";
}
?>
你確定文件路徑是否正確?檢查file_get_contents是否不返回false。 – roptch
as dreamstate說:check path - 你可以使用[getcwd()](http://php.net/manual/en/function.getcwd.php)來檢查'當前工作目錄' – furas
如果我回顯$ content;任何地方,我都可以在我的網上獲得文件內容。所以路徑是正確的。 – helpmepls