Question

hello to all at stackoverflow. (my first post) : ) i wrote this script

$file = glob("*.php");  // list all .php files
$findfile = array_search("index.php", $file); // search array for index.php
unset($file[$findfile]);  // remove index.php from array
sort($file, SORT_NUMERIC); // sort array 
foreach($file as $file){ include_once($file);} // include files in page

the files are 1.php,2.php,3.php etc

everytime i run it the files get included at the top of the page. i need the files in the middle, what am i doing wrong.

Thats the whole page as it looks for now

<?php
if(isset($_POST['ta'])){
$ta = $_POST['ta'];
if($ta != "" && strlen($ta) > 1 ){
$ta = preg_replace('#[^a-z0-9 !?.,]#i', '', $ta);
$usertextinput = '<p class="important">'.$ta.'</p>';

$pho = count(glob('*.php'));
$username_file = ($pho + 1) . ".php";
$createuser = fopen($username_file, 'w');
fwrite($createuser, $usertextinput);
header("location: index.php#bottom");}}

$userpage = '<p class="important"><span>Posts\'s:</span><br />
[username] Has 1 post's To Date.</p>';?>

$file = glob("*.php");
$findfile = array_search("index.php", $file);
unset($file[$findfile]);
sort($file, SORT_NUMERIC);
foreach($file as $file){ include_once($file);}

$userpage .= '<form name="text" method="post" action="">
<textarea name="ta" placeholder=" Enter Your Comment\'s Here ">
</textarea><br />
<a name="bottom"></a>
<p class="sub"><input type="submit" value="Post To Page" /></p>';
?>

im building a post wall (no database)

Was it helpful?

Solution

Give this a go. It will have the form's input on top,
then the Posts's: [username] Has 1 post's To Date. followed by the included files.

It's basically a placement issue.

<?php
if(isset($_POST['ta'])){
    $ta = $_POST['ta'];
if($ta != "" && strlen($ta) > 1 ){
    $ta = preg_replace('#[^a-z0-9 !?.,]#i', '', $ta);
    $usertextinput = '<p class="important">'.$ta.'</p>';

$pho = count(glob('*.php'));
$username_file = ($pho + 1) . ".php";
$createuser = fopen($username_file, 'w');
    fwrite($createuser, $usertextinput);
    header("location: index.php#bottom");
    }
}

$userpage = '<form name="text" method="post" action="">
<textarea name="ta" placeholder=" Enter Your Comment\'s Here ">
</textarea><br />
<a name="bottom"></a>
<p class="sub"><input type="submit" value="Post To Page" /></p>';

$userpage .= '<p class="important"><span>Posts\'s:</span><br />[username] Has 1 post\'s To Date.</p>';

echo $userpage;

$file = glob("*.php");
$findfile = array_search("index.php", $file);
    unset($file[$findfile]);
sort($file, SORT_NUMERIC);
    foreach($file as $file){
     include_once($file);
    }

?>

OTHER TIPS

The reason why it isn't working, is because you are terminating the php code here:

[username] Has 1 post's To Date.</p>';?>

Remove the ?> and escape the single quote near post's; so the code block will look like this:

$userpage = '<p class="important"><span>Posts\'s:</span><br />
[username] Has 1 post\'s To Date.</p>';

$file = glob("*.php");
$findfile = array_search("index.php", $file);
unset($file[$findfile]);
sort($file, SORT_NUMERIC);
foreach($file as $file){ include_once($file);}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top