We hope you enjoy your visit.

You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
PHP Script; file creator
Topic Started: Mar 17 2005, 08:10 PM (744 Views)
shockwave-
My other title is a Ferrari
[ *  * ]
hey, i just started off with PHP, and i know that there is a script that is avalible, but I'm not sure what it is.

What I want, is a script that once someone submits some info, using a textarea or text input or whatever, it copies it onto a file, and gives them the link.

I'd appriciate it if someone could provide a link or somthing. :D
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
You want something that saves info into a text file, then gives a link to the file? If so,

Code:
 

<form name="info" action="?act=save" method="post">
<input name="name" type="text" size="40" maxlength="25" /> Name
<textarea name="comment" cols="55" rows="5" wrap="hard"></textarea>
<input type="submit" name="Submit" value="Submit" />
</form>
<?php
function makeRandom() {
 $salt = "abchefghjkmnpqrstuvwxyz0123456789";
 srand((double)microtime()*1000000);
     $i = 0;
     while ($i <= 7) {
           $num = rand() % 33;
           $tmp = substr($salt, $num, 1);
           $srand= $srand. $tmp;
           $i++;
     }
     return $srand;
}
if (!empty($submit)) {
$filename = makeRandom();
$file = fopen("".$filename.".txt", "r");
$read = fread($file, filesize("".$filename.".txt"));
fclose($file);
echo "<a href=\"".$filename.".txt\">The File</a>";
}
?>


It *should* work, have not tested it..

EDIT: BTW, I believe that this should be in Coding and Scripting.. :P
EDIT 2: If in *nix/linux servers, the folder containing the script has to be chmodded to 777.. Although maybe 666 would work.. :)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
does not seem to work.

All that happens, once i submit my info, is the URL changes to this:

http://www.mysite.com/somedirectory/filecreator.php?act=save
Offline Profile Quote Post Goto Top
 
Rory
i;m a mess
[ *  *  *  *  *  *  * ]
Topic Moved
Offline Profile Quote Post Goto Top
 
Ben
Member Avatar
Quantum-locked when observed.

shockwave-
March 17, 2005 07:56 PM
does not seem to work.

All that happens, once i submit my info, is the URL changes to this:

http://www.mysite.com/somedirectory/filecreator.php?act=save

Yes, because the function is there but it isn't being called. ;) PHP is case-sensitive when it comes to variables, so $Submit is different from $submit. Plus, if you have register_globals off, it might not work without using the $_POST array.

Change your code to this:

Code:
 

<form name="info" action="?act=save" method="post">
<input name="name" type="text" size="40" maxlength="25" /> Name
<textarea name="comment" cols="55" rows="5" wrap="hard"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
function makeRandom() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
    $i = 0;
    while ($i <= 7) {
          $num = rand() % 33;
          $tmp = substr($salt, $num, 1);
          $srand= $srand. $tmp;
          $i++;
    }
    return $srand;
}

$submit = $_POST["submit"];

if (!empty($submit)) {
$filename = makeRandom();
$file = fopen("".$filename.".txt", "r");
$read = fread($file, filesize("".$filename.".txt"));
fclose($file);
echo "<a href=\"".$filename.".txt\">The File</a>";
}
?>
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
Hmm.. Well, when i do type in some info, then hit submit, it comes up with a couple of errors at the bottom, then gives me a link to the file, Then, when i do click the file, it's a 404 Error. I can't seem to figure out why it's not working.
Offline Profile Quote Post Goto Top
 
Sani
Member Avatar
Member
[ *  *  *  *  * ]
Use this:

Code:
 

<form name="info" action="?act=save" method="post">
<input name="name" type="text" size="40" maxlength="25" /> Name <br />
<textarea name="comment" cols="55" rows="5" wrap="hard"></textarea>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
function makeRandom() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
   $i = 0;
   while ($i <= 7) {
         $num = rand() % 33;
         $tmp = substr($salt, $num, 1);
         $srand= $srand. $tmp;
         $i++;
   }
   return $srand;
}

$submit = $_POST["submit"];

if (!empty($submit)) {
$filename = makeRandom().".txt";
@touch($filename);
$file = fopen($filename, "w+");
fwrite($file, "$name\n$comment");
fclose($file);
echo "<a href=\"$filename\">The File</a>";
}
?>


It works, Already tested it.. :)
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
um.. doesn't work for me. Same thing happens as last time. it doesn't actually create the file. Am i doing somthing wrong?
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
If you're on a Linux server, you must CHMOD the directory to world-writable (0777) before being able to create files in it.
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
uh huh...

like i said, i'm pretty new to PHP and stuff, so could someone explain that?
Offline Profile Quote Post Goto Top
 
Seth
Member Avatar
I has a pony
[ *  *  *  *  *  *  *  *  * ]
Posted Image

:rofl: I love that picture. Clicky!
Offline Profile Quote Post Goto Top
 
shockwave-
My other title is a Ferrari
[ *  * ]
oh, man. It worked. Thanks Seth. :D

Oh, this probably isn't possible, but hey, PHP can do a lot of things. I want to avoid my disk space overrunning. Is there a way I could make it delete the file in X amount of days?

Also, is there a way that i can get the file makers' IP addresses (to avoid spammers) :no:
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Technology Chat · Next Topic »
Add Reply