On my website, I have an upload story feature with a user written title and story. It uploads it as a text file in a directory. Is there a way to list the content of these files using php or anything? Also, I'd like to only show like 200 chars of the story, and have a 'show full story' button, that would show the full story (I'll use jQuery for this).
Here is my current code for this, though it doesn't work and i can't figure out the problem :(
<head>
<style type="text/css">header {font-size:20pt; color:#ff00e8;} footer {text-align: left; font-weight:bold; padding-left: 5px;} article {padding:20px;}</style>
</head>
<body>
<h2><a href="../php/upload_story.php" style="font-size:15pt; color:#ff00e8; text-decoration: none;" id="tortenetfeltolt">Van egy jó történeted? Írd meg és kikerülhet az oldalra!</a></h2>
<?php
$dataArray = array();
//Number of chars for the string
$num = 200;
//Check if DIR exists
if ($handle = opendir('../php/biralas_tortenetek/')) {
//Loop over the directory
while (false !== ($file = readdir($handle))) {
//Strip out the . and .. files
if ($file != "." && $entry != "..") {
// $dataArray[] = array();
//Store file contents
$filecontent = file_get_contents($file);
//Split the content and store in array
$length = strlen($filecontent);
$dataArray[] = array(substr($filecontent, 0, $num), substr($filecontent, $num, $length ));
}
}
//close the dir
closedir($handle);
}
?>
<?php foreach($dataArray as $data) { ?>
<div class="visible">
<?php echo $data[0]; ?>
</div>
<div class="hidden">
<?php echo $data[1]; ?>
</div>
<?php } ?>
</body>