Jump to content

PHP Blocks


JREAM

Recommended Posts

Can someone please help me I've been stuck for a long time now --

 

I can't get it right and I dont know what its called.

I think this is some kind of PHP Block Module thing but I cant' find anything like this for a text file..

Its almost like a TPL engine but not even close to that size.. Thats all I could think it relates to.

 

This is what Im trying to do,

 

1. Text files in sit in a directory.

2. In PHP: Each textfile is put into it's own <textarea> (So it can be edited) (See my loop below)

3. In PHP: You can change the textarea and save it to the file you it applies to.

 

(Ignore 4 if this is too much to ask I dont care I might be able to do it)

4. Possibly a way to have a form to create new ones (It would create a blank txt file, and add a new form to the list)

 

End: The goal is that Im going to use the title of say, block1.txt, and do a string like ###block1.txt### and it will output the code on the main page.

 

 

This is what I have for the directory, can anyone tell me if Im close?

$path = "/block/";
$dir_handle = @opendir($path);

while ($file = readdir($dir_handle)) {

// This is a file name
echo "<input type='text' value='$file'>";

// How would I make this read the txt file contents?
echo "<textarea>$file</textarea>";

echo "<input type=submit value=send>";
}

closedir($dir_handle);

 

 

Link to comment
Share on other sites

Here is where Im at!

 

I've got to figure out how to write them based on the $file name for the submit I think,

 

Why do I get this? (The content shows up)

Warning: file_get_contents(block1.php) [function.file-get-contents]: failed to open stream: No such file or directory in C:\Active_Projects\X11\cms\core\admin.blocks.php on line 54

 

function showblocks() {

$path = "data/blocks/";
$dir_handle = @opendir($path);

echo "<h2>Edit Blocks</h2>
<form action='?action=showblocks&do=editblock' method='post'>
<table>";

while ($file = readdir($dir_handle)) {
if ($file != "." && $file != "..") {

echo '
<input type="text" value=' . $file .'><br />
<textarea>' . file_get_contents($file) . '</textarea><br />
<input type="submit" name="'. $file .'" class="b" value="Save Block"><br /><br />';
}

}

closedir($dir_handle);

echo "</form>";
}

Link to comment
Share on other sites

too much mess, I guess im going the fixed route:

 

I can't figure out why the forms act like twins, is there someplace i need to park the $bn variable that I missed so they don't update the different forms as the same?

 

function showblocks() {
   block('block-1');
   block('block-2');
}

function block($bn){

$name = $bn;
if (isset($_POST['$bn'])) {

$filename = "data/blocks/" . $name . ".php";
$text = $_POST['$bn'];

$fp = fopen ($filename, "w");
if ($fp) {
	fwrite ($fp, $text);
	fclose ($fp);
	}
}
print '<h2>Edit: ' . $name . '</h2>';
print '
	<form name="'.$bn.'" method="post" action="?action=showblocks">
	<textarea name="'.$bn.'" cols="90" rows="30">';

include('data/blocks/' . $name . '.php');

print '</textarea></div>';
print '<input class="b" type="submit" name="sub" value="Save Changes" />';
print '</form>';
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.