Page 1 of 1
File permission questions
Posted: Fri Jun 30, 2006 3:18 am
by akimm
My purpose is to create a textfile that doesn't exist, consistent completely of form input, a content management system, I can't use mysql so I need to use flatfiles.
Is there anyway I can create a textfile in /somedirectory/somearticle
However I want the textfiles created as some submit these articles, like the first article to be article1.txt.
NOTE: I am not asking, nor do I want anyone to write code for me, I just need to know whether or not you can actually do what I'm trying to do.
Posted: Fri Jun 30, 2006 3:25 am
by Luke
Didn't we already go over this? I remember like 3 threads about this only a week ago at the most. Did you forget? How come you can't use database? Are you scared they are going to be too hard? Files are more difficult to work with than databases if that's the case. Databases are MUCH easier to manage. File management can be pretty crappy.
Posted: Fri Jun 30, 2006 3:25 am
by JayBird
Yes, it is possible. Read up on all the file functions
http://uk.php.net/manual/en/ref.filesystem.php
Posted: Fri Jun 30, 2006 3:28 am
by Luke
Yes
Posted: Fri Jun 30, 2006 3:29 am
by akimm
I did post this three times, and three times peoples help failed, must you be so terse, all I wish to know is if it's possible to do what I want to do, if you don't want to help don't come to this, sorry I don't know everything, and sorry the help that was provided wasn't sufficient to help out my moronic ass. I wish I could answer my questions, I wish the 150 inquiries on google could, but apparently I'm still stuck. I am a broke college student, I do not have the money to purchase the mysql database. Please just answer my question or be on your way, sorry i'm such a problem with my constant repost, perhaps I should just forget about this forum if that is such a burden.
Posted: Fri Jun 30, 2006 3:33 am
by Luke
No... it's not that you are a burden. Everybody here is happy to help. It's the fact that you have started like 4 or 5 threads to solve one problem. Everybody has been helpful to you and you call them rude. Still... I'm happy to help. Just don't understand why you are asking this question when it has been answered 4 or 5 times.
So, let's go back to your code that you posted already 4 times and we can try and get this resolved for you.
You must realize this is the internet, so things may come off as rude, but that's because there isn't a way to emphasize caring and concern other than this:

I call people rude
Posted: Fri Jun 30, 2006 3:36 am
by akimm
When they talk down to me, scold me as you did. I understand what you're saying with the multiple posts, but never did any help I receieve solve my problems, I then began to rewrite the code on my own, and came to the conclusion that even with constant checks with php.net, and other sources, and still the problem was not solved.
Well excuse my misunderstanding
Posted: Fri Jun 30, 2006 3:37 am
by akimm
I guess you are right about that.
Posted: Fri Jun 30, 2006 3:39 am
by Luke
So, what exactly is this project you are doing? Can you give me a little more background... maybe I can help you come up with a solution.
I want a program that
Posted: Fri Jun 30, 2006 3:44 am
by akimm
I have this form, on 5.htm. With 4.php I have a counter iterate and from that iteration I take the number and add it to article, idealy, the first article submitted should be article1.txt and so forth. I have tried a+ w+ and now x+ to try to mittigate the writing process of this article to the directory.
Code: Select all
<form method='POST' action='4.php'>
<p><b>Your name</b>
<input type='text' name='name' size='30'></p>
<p><b>Your email</b>
<input type='text' name='email' size='30'></p>
<p><b>article</b>
<TEXTAREA NAME='article' COLS='120' ROWS='20' WRAP='virtual'></TEXTAREA></P>
<p><input type='submit' name='submit' value='submit your aritlce'></p>
Code: Select all
<?php
$myfile = "count.txt";
//we assign our file name to the variable we'll use to handle it
if(file_exists($myfile))//if the file exists
{ //we run our counter script
$var = fopen( $myfile,'r+');
//opens in read and write mode our file
$visits = fread($var,filesize($myfile));
//puts the content of the file for its whole lenght
rewind( $var );
//resets the file position indicator to the beginning
$visits++; //increments the actual number of vists by 1
fwrite($var, $visits);
//writes on the variable the actual (incremented) value
fclose($var);//closes our file reference
}
else
{
// print "File $myfile doesn't exist...";
Die();
//if the file doesn't exist prompts a warning and kills the script
}
$file = '/articles/article' . $visits . '.txt';
if ($_POST['name'] == "") {
echo "please provide a name";
}
if ($_POST['email'] == "") {
echo "Please provide an email";
}
if ($_POST['article'] == "") {
echo "If you're submitting an article, you'd need the actual article. Try again ";
}
// recognize what i want from user
// variable to concocatanate to append user info
$user = $_POST['name'] . $_POST['email'] . $_POST['article'];
$handle = fopen($file, 'x+');
// start an iteration that will add 1,2,3,4,5,6 and so on to each article
// added
if(file_exists($file)) {
Die();
} else {
fwrite($handle, $user, 'w+') . fclose($handle);
}
?>
Posted: Fri Jun 30, 2006 3:53 am
by Weirdan
It seems like it should work.
Except of this bit:
Code: Select all
// recognize what i want from user
// variable to concocatanate to append user info
$user = $_POST['name'] . $_POST['email'] . $_POST['article'];
$handle = fopen($file, 'a+');
// start an iteration that will add 1,2,3,4,5,6 and so on to each article
// added
if(file_exists($file)) {
Die();
} else {
fwrite($handle, $user, 'x+') . fclose($handle);
}
which should be:
Code: Select all
// recognize what i want from user
// variable to concocatanate to append user info
$user = $_POST['name'] . $_POST['email'] . $_POST['article'];
if(file_exists($file))
die();
$handle = fopen($file, 'a+');
// start an iteration that will add 1,2,3,4,5,6 and so on to each article
// added
fwrite($handle, $user);
fclose($handle);
Posted: Fri Jun 30, 2006 3:53 am
by JayBird
DO NOT START TOPICS ON THE SAME SUBJECT!!!
Use your other thread to continue the discussion.
If noone could help int he previous topics, no need to start a new one