Jump to content

Recommended Posts

Hey, I got me a very basic flatfile guestbook that im modifying for my website..

 

I need to have it where it created the txt file for the files page..

 

Like as you can see

http://animatorhost.com/index.php?page=viewf&file=338i0.jpg&name=NapalM

 

I have the page that desplays that uploaded file, and it has a basic comment system under..

 

My issue is, to desplay the comments i use a include.. But i cant find a way to just have it when a persion trys to create a comment it automaticly creats the text file that i have it set up too.. like i have the text file set up to the name of the file .txt

 

like, 338i0.jpg.txt..

 

But the only way i can get it to work is by its self when a users posts a comment it will create it but give the user a error saying its not found (this happens for the first commenter) because the file has not been created yet..

 

 

Do you get what im trying to say?

 

 

heres what i was trying first..

 

<?php

$myFile = "posts/$file.txt";

if(!file_exists("posts/$file.txt"))

{

die("Sorry No Comments!");

$fh = fopen($myFile, 'w') or die("can't open file");

fclose($fh);

}

else

{

$file=include("posts/$file.txt");

}

?>

 

Hope some one can help -__-

Link to comment
https://forums.phpfreaks.com/topic/121765-txt-file-creation/
Share on other sites

 

heres what i was trying first..

 

<?php

$myFile = "posts/$file.txt";

if(!file_exists("posts/$file.txt"))

{

die("Sorry No Comments!");

$fh = fopen($myFile, 'w') or die("can't open file");

fclose($fh);

}

else

{

$file=include("posts/$file.txt");

}

?>

 

include does not return a value, so you cant assign it to a variable. Instead your should use file_get_contents.

Link to comment
https://forums.phpfreaks.com/topic/121765-txt-file-creation/#findComment-628174
Share on other sites

You copyed and pasted that from another site, i know cause i used it before.. An what it was doing is it just kept creating the file over and over when you would try and post the comment. so it wouldent add what you wrote cause it would write over it with the new text file..

Link to comment
https://forums.phpfreaks.com/topic/121765-txt-file-creation/#findComment-628534
Share on other sites

fopen will attempt to create the file if it doesn't exist, it shouldn't overwrite the file. In order for this to happen you should use the appropriate mode parameter for fopen.

 

As a side note, matthew798 code is valid it should append the string "Bobby Bopper\n" to YOURFILE.txt each time the page loads.

 

If its not working correctly then may be its a file permission problem.

Link to comment
https://forums.phpfreaks.com/topic/121765-txt-file-creation/#findComment-628903
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.