我搜索了几乎类似的问题,但没有一个给我正确的答案。我在 if else 语句中有一个完整的file_exist代码。但是当我将它放在一个函数中时,它就不再起作用了。这是代码:
if (file_exists($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.txt")) {
$myFile = ($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.txt");
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
echo "The file exists." ;
}
else {
echo "The file $filename does not exist";
}
当我将它放在一个不起作用的函数中时:
function readexisting(){
if (file_exists($_SERVER['DOCUMENT_ROOT']."/Project/events/folder-01/event-01.txt")) {
$myFile = ($_SERVER['DOCUMENT_ROOT']."/Alchemy/events/folder-01/event-01.txt");
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;
echo "The file exists." ;
}
else {
echo "The file $filename does not exist";
}
}
另外,我想在图像点击事件中调用该函数。如果有帮助,这是代码:
<div class="Thumb popup_element shadow clearfix" id="u2413"><!-- group -->
<img class="grpelem" id="u2471" alt="This Week's Events" src="images/blank.gif" onclick="readexisting()"/><!-- state-based BG images -->
</div>
我希望你能帮我解决这个问题。非常感谢你!