Log in

View Full Version : Create new folder and .TXT file



Spinethetic
06-17-2008, 01:00 AM
<?
if($_POST['Submit']){
$open = fopen("$username/$topurl.txt","w+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "My notes:<br />";
$file = file("$username/$topurl.txt");
foreach($file as $text) {
echo $text."<br />";
}
}else{
$file = file("$username/$topfilename.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Hello, its me again. I have gotten a working login and registration system on my site and I would like to make it so that when a new user logs in and views a page, a new subdirectory is created named after the visitors username, if it does not already exist;

Simeltaniously creating a new .TXT file named after the filename of whatever webpage they are on, if it does not already exist; if it does exist than the file contents are to be loaded into the TEXTAREA for further appending by the user.

I know of the fcreate function, but I am not familiar with its paremeters or how to 'work it' :)

Spinethetic
06-17-2008, 02:39 PM
Ok Ive worked a bit more and gotten thus far. The problem I keep encountering is that $username keeps coming empty instead of storing the logged-in visitors username, instead a new folder is created titled $username. :confused:
And $username is supposed to hold a value because I use it to display a welcome message on the same page. And I've provided a+ as the paremeter, yet no file is being created. I just get error msg that file does not exist.


<?php
mkdir('$username', 0777);
if($_POST['Submit']){
$url = $_SERVER['REQUEST_URI'];
$open = fopen("$username/$url.txt","a+");
$text = $_POST['update'];
fwrite($open, $text);
fclose($open);
echo "My notes:<br />";
$file = file("$username/$url.txt");
foreach($file as $text) {
echo $text;
}
}else{
$url = $_SERVER['REQUEST_URI'];
$file = file("$username/$url.txt");
echo "<form action=\"".$PHP_SELF."\" method=\"post\">";
echo "<textarea Name=\"update\" cols=\"50\" rows=\"10\">";
foreach($file as $text) {
echo $text;
}
echo "</textarea>";
echo "<input name=\"Submit\" type=\"submit\" value=\"Update\" />\n
</form>";
}
?>


Best Regards
~Spine :)

Jas
06-18-2008, 03:42 AM
You put the var in single quotes.
This:

mkdir('$username', 0777);
Should be:

mkdir("$username", 0777);
or

mkdir($username, 0777);

Harishpawar
03-23-2009, 08:12 PM
I am harish Pawar what i was looking out was, when i enter some data in the
HTML form then that dynamic data should get saved in the .txt file with
when i saw this it was some where near to this can u please help me on this



You put the var in single quotes.
This:

mkdir('$username', 0777);
Should be:

mkdir("$username", 0777);
or

mkdir($username, 0777);

bluewalrus
03-24-2009, 02:03 AM
I think your searching for what I was a while ago and the answer can be found here: http://www.dynamicdrive.com/forums/showthread.php?t=41230&highlight=make+text+file&page=4