I have searched for almost similar questions but none of those gave me the right answer. I have a fully working file_exist code in if else statement here. but when i placed it inside a function it doesn't work anymore. Here's the code:
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";
}
When I place it inside a function which isn't working:
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";
}
}
Also, I want to call the function in image click event. here's the code if it would help:
<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>
I hope you could help me with this. thank you so much in advance!