PDA

View Full Version : saving large data as txt then retreiving them


Trusten
11-21-2002, 10:15 AM
hello, two things.

1. i'm trying to build a page where people can upload their stories. i understand that this is a lot for the database to handle so someone suggested the files be saved as txt then call the file agian.

it sounded like a good idea. sadly, most people save their files as 'txt' files, but when i tried to retrieve it by way of include, then it simply will not word wrap.

i know about nl2br

so i tried to echo it. Echo only shows the txt file's path, so that will not work.

what command can i use, that will include the file, but use nl2br along with is, so tht the line breaks will show up.

please help.


2. whenever i save the file onto my server, it takes on the permisson of 600, which is a VERY bad thing. how can i force it to stop doing this?

i believe these are the defalt permssions if none are set.


if you can give me a hand, i'd appreciate it.

Thank you.

Wichetael
11-21-2002, 11:27 AM
You can simply read in the file with the file functions as fopen, etc. then you can change the newlines into linebreaks.

As to the permissions, why would that be a bad thing, that means that only the user who made the file has read/write access, and since the user who made the file is the user that started the httpd process I figure that that's a good thing...

People should not be able to link to the file directly and by all accounts that's a good situation. This way only you have access to the file.

Trusten
11-21-2002, 12:16 PM
well it keeps saying apache made the file. how do i make it see that i made it?

and couild you give me an exampe of how that open code would look?

Wichetael
11-21-2002, 12:44 PM
Well, you actually do not create the file but apache does, and since only apache will have to be opening the file that would be ok.

btw you can if you wish change the permissions with chmod and chown, they're regular file functions in php.

int chmod ( string filename, int mode);

int chown ( string filename, mixed user);

About the simplest way would probably be:

if ($fp = fopen('textfile.txt', 'r')) {
$buf = fgets($fp, 4096);
while (!feof($fp)) {
echo nl2br($buf);
$buf = fgets($fp, 4096);
}
fclose($fp);
}

Trusten
11-21-2002, 01:19 PM
thank you.

i'm not sure where that chmod code would go, but i'll look.

i have no trouble with apahce creating the file, but when it comes time to back up, guess what? i can't download them or anything, so i have to go into each one and save manually.

it's a nightmare.

Wichetael
11-21-2002, 01:32 PM
You should call the chmod right after you save the file to disk.

As for the backup, why don't you simply make a back-end for your site that allows you to backup/import all the files in a single package, you can use one of the compression libraries that come with php, easiest would probably be to use the zlib library to produce a .gz file which you can download.

Trusten
11-21-2002, 01:39 PM
huh?


<?
if (Trusten > knowledge of php higher than 0)
{Trusten = "rich"}
else
{Trusten = "visiting forums desperately]

?>

what'd you just say???


*vacant stare*

Wichetael
11-21-2002, 01:58 PM
You can use the zlib library incorporated into php (documented here (http://www.php.net/manual/en/ref.zlib.php)) to write all the text files into a single gz file for backup puposes. Then you only need to download the gz file.

Trusten
11-21-2002, 02:00 PM
danke schoen.

ich liebe dich.


*cries*

vielen danke.

Wichetael
11-21-2002, 02:16 PM
No problem at all, good luck with the rest of your site.