我已经寻找过几乎类似的问题但这些都没有给我正确的答案。我有一个完全workingif 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>
我希望你能帮我解决这个问题。提前非常感谢!
With onclick=
您分配的是 JavaScript 事件处理程序,而不是 PHP 函数。
我不知道您的代码应该做什么,但也许您可以在将某些内容发布到您的文件时执行该函数。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)