Closed Thread Icon

Topic awaiting preservation: PHP and SSI (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=12734" title="Pages that link to Topic awaiting preservation: PHP and SSI (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP and SSI <span class="small">(Page 1 of 1)</span>\

 
CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 05-13-2003 19:36

Hi all. I know I probably bug the hell out of you all with these questions but I have fought with this for quite some time. Here is what I have.
A page with a form:

code:
<form method="POST" action="posts.php">
<p />name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="TEXT" name="name" size="35" maxlength="100"><br/>

<p />email:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="TEXT" name="email" size="35" maxlength="100"><br/>

<p />comment:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<textarea name="comment" rows="15" cols="50"></textarea><br />

<p /><input type="SUBMIT" name="submit" value="submit" class="submit">
</form>



Then the PHP script is called from this form which is:

code:
<?
//get current date and time
$month = date("M");
$day = date("d");
$year = date("Y");
$time = ":".date("H").":".date("i").":".date("s");


//use a time stamp thingy to sepearte files
$identifier = time();

//save the post as a *.dat file
$filePointer = fopen("posts/{$identifier}posts.dat", "a+");

//formating each posting. . .
fputs($filePointer,"

<p class=\"dateText\">$month,$day, $year &#0124; &#0124; $time\r\n</p><br />
<div class=\"byText\">Posted by: $name\r\n</div>
<p class=\"commentText\">$comment\r\n</p><br />
<div class=\"emailText\"><a href=\"$email\">$email\r\n</div>
<hr />"
);

//close it up
fclose($filePointer);

//open the posts folder
$dir_name = "posts/";

$dir = opendir($dir_name);
$file_list = "";

//loop through the directory for each *.dat file
while ($file_name = readdir($dir)) {
if (preg_match("/dat\$/i", $file_name)) {
$file_list .= "$dir_name$file_name";
}
}

//close the directory
closedir($dir);

//include them in the page.
include ($file_list);


?>




The problem is with the include. I can make it echo each of the files in the listing but I can't figure out how to "open" each on of them for them to
be displayed in the page. Does that make sense? If not let me know and I will try to post more info. But right now that is as good as I can explain it.

Thanks in advance.

Later,

C:\


~Binary is best~

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-13-2003 20:01

with out reading any of your code, just you comment... check out fopen() and fputthrough() (and fread() and fclose() as well). that should get you started.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 05-13-2003 20:04

CPrompt:

quote:
I can make it echo each of the files in the listing but I can't figure out how to "open" each on of them for them to be displayed in the page. Does that make sense?



Nope

Do you mean that you want to store the includes as a variable so you can drop them into your page later on rather than dump then contents into the page wherever the script is?

If so then I don't think it is possible to do:

$output .= include();

I think you'll need to read the contents of the file in from the included file.

___________________
Emps

FAQs: Emperor

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-13-2003 22:22

if you want to get the output of an included file into a variable,
you'll need to use ob_start() and assorted functions...

for what it's worth...

code:
foreach ($listOfFiles as $aFile)
{
ob_start();
include($aFile);
$text = ob_get_contents();
ob_end_clean();
}



edit by Skaarjj: Just fixin' some bad UBB code

[This message has been edited by Skaarjj (edited 05-14-2003).]

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 05-14-2003 00:25

OK, well. . . I didn't think that my post was that cryptic but then again I wrote it

Here is what I am doing:

I have my main directory. This directory has a PHP file that has the form. The form calls a PHP script that is located in the same directory. With me so far?

The PHP script creates a file with the information that is supplied from the form. These files are stored in a folder under the main directory. OK?

Now, what I meant by I can "echo" the files that are in the "Post" directory is that way down at the bottom of the PHP script, where the "include($file_list), if I change that to "echo ($file_list), it will print out all the NAMES of the files, not what is actually contained in them.

With me?

. . . . . What I am needing to do. . . . .

I would like for the script to write a file for each submission from the form to the "posts" directory. Then after it is there, "include" the information that is contained in each file to the page. All that is being written to the files is HTML.

Now I can have the script save each of the postings from the form to a flat text file and it will display that. But, I want each one of the postings to be sepearte. Hense the time stamp for the file name for each one.

Does this make any more sense? Did I just repeat myself? Is it now more confusing?

Anyway, thanks in advance. . .

Later,

C:\


~Binary is best~

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-14-2003 00:48

I get it. (I think)

you want to add the posted information to the file and then include all the files.

Now this issue you are probably hitting is with this code

code:
while ($file_name = readdir($dir)) {    
if (preg_match("/dat\$/i", $file_name)) {
$file_list .= "$dir_name$file_name";
}
}



because $file_list is just going to be a string like xxxxxx.datxxxxx.datxxxxx.dat.....

Easier to do and because you have the loop already is instead of building the file list, just include the file in the loop (you can do this with include but not require I think)

code:
while ($file_name = readdir($dir)) {    
if (preg_match("/dat\$/i", $file_name)) {
include ($dir_name.$file_name); // this may break without the period
}
}



failing that you could just make $file_list an array and then just pop things on there

code:
$file_list = array()
while ($file_name = readdir($dir)) {
if (preg_match("/dat\$/i", $file_name)) {
array_push($file_list, "$dir_name$file_name");
}
}



then loop through and include the files one at a time

code:
foreach ($file_list as $var) include($var); // shorthand loop





.:[ Never resist a perfect moment ]:.

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 05-14-2003 00:51

In another note I don't think you want to escape the dollar sign in your regular expression. Without testing it I'm pretty sure that you are killing it's regexp meaning (dat at the end if the file name) and instead making your regular look literally 'dat$' what you probably want is

'/\.dat$/', $file_name

so it looks for files that end with '.dat'



.:[ Never resist a perfect moment ]:.

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 05-14-2003 00:55

yep you got it Bit. That is what I am trying to do. Might not be the best way to do it but I am learning

I will try them all out.

Thanks.

Later,

C:\


~Binary is best~

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 05-14-2003 04:02

actually bit, your first post is what I was trying to do. I guess I was on the right track but not quite there I am going to test the other just to see the outcome of them.

I believe this was the hard part of what the finished product will be (famous last words )

Anyway, thanks for the help. It is much appreciated

Later,

C:\


~Binary is best~

« BackwardsOnwards »

Show Forum Drop Down Menu