| |
pleasant Senior Googler


Joined: 31 Jul 2004 Location: australia 1094.80 GC$
Items
|
Posted: Sun Oct 24, 2004 10:59 pm Post subject: I need help with this bit of code - php |
|
|
|
this code is for a page for staff on my site to use to edit some pages.
| Code: | <?php
$handle = fopen("downloads.html", "r");
?>
<?php
$filename = 'downloads.html';
$somecontent = "Add this to the file\n";
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
<?php
$handle = fopen('downloads.html', 'r');
fclose($handle);
?> |
instad of it just adding "Add this to the file"
i want a box to come up and they write what ever they want into it. _________________
 |
|
| Back to top |
|
|
zirias Noogle

Joined: 24 Oct 2004 Location: Germany 858.60 GC$
Items
|
Posted: Mon Oct 25, 2004 7:58 am Post subject: |
|
|
|
Just do something like
| Code: | $somecontent = $_POST['somecontent']
if ($somecontent=="") {
echo '<form method="post" action="'.$PHP_SELF.'">
<textarea name="somecontent"></textarea>
</form>
...';
} else {
// rest of your script
} |
Greets, Felix |
|
| Back to top |
|
|
pleasant Senior Googler


Joined: 31 Jul 2004 Location: australia 1094.80 GC$
Items
|
Posted: Mon Oct 25, 2004 9:39 pm Post subject: |
|
|
|
i get an undexpected T_IF on line 8 this is what i put just incase i put it in the worng place:
| Code: | <?php
$handle = fopen("downloads.html", "r");
?>
<?php
$filename = 'downloads.html';
$somecontent = $_POST['somecontent']
if ($somecontent=="") {
echo '<form method="post" action="'.$PHP_SELF.'">
<textarea name="somecontent"></textarea>
</form>
...';
} else {
// rest of your script
}
// Let's make sure the file exists and is writable first.
if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
} else {
echo "The file $filename is not writable";
}
?>
<?php
$handle = fopen('downloads.html', 'r');
fclose($handle);
?> |
_________________
 |
|
| Back to top |
|
|
intelliot Site Admin

Joined: 01 May 2004
18653.45 GC$
Items
|
Posted: Mon Oct 25, 2004 9:40 pm Post subject: |
|
|
|
| Just use a standard HTML form. You are missing a semicolon in your code. |
|
| Back to top |
|
|
zirias Noogle

Joined: 24 Oct 2004 Location: Germany 858.60 GC$
Items
|
Posted: Tue Oct 26, 2004 1:24 am Post subject: |
|
|
|
That was example code. Not tested and "..." means anything you like to complete your HTML output. In the first line, I forgot the ";". Hey, I thought you knew PHP ... don't you?
Greets, Felix |
|
| Back to top |
|
|
jose.mira Noogle

Joined: 22 Oct 2004 Location: Portugal 741.35 GC$
Items
|
Posted: Wed Oct 27, 2004 5:38 pm Post subject: |
|
|
|
you are missing the semicolon in line 7:
| Quote: | | $somecontent = $_POST['somecontent'] |
that's why you get an error in line 8  _________________
 |
|
| Back to top |
|
|
pleasant Senior Googler


Joined: 31 Jul 2004 Location: australia 1094.80 GC$
Items
|
Posted: Sun Oct 31, 2004 2:08 am Post subject: |
|
|
|
it just says that downloads.html is not writable but it is _________________
 |
|
| Back to top |
|
|
zirias Noogle

Joined: 24 Oct 2004 Location: Germany 858.60 GC$
Items
|
Posted: Sun Oct 31, 2004 3:22 am Post subject: |
|
|
|
I don't think this is a PHP related problem. If your script runs on a multiuser system, the file has to be writable for the user running the webserver. On many linux-systems, you can use the group "www-data".
Greets, Felix |
|
| Back to top |
|
|
Ashes Senior Googler


Joined: 26 Sep 2004 Location: Bosom of Dixie 1601.05 GC$
Items
|
Posted: Sun Oct 31, 2004 5:34 am Post subject: |
|
|
|
You probably need to chmod the file to 777. _________________ This is a sig. Isn't it nice?
pushing through [dot] com |
|
| Back to top |
|
|
zirias Noogle

Joined: 24 Oct 2004 Location: Germany 858.60 GC$
Items
|
Posted: Sun Oct 31, 2004 5:46 am Post subject: |
|
|
|
| Ashes wrote: | | You probably need to chmod the file to 777. |
No, you don't. You don't want to make files world-writable. Group-writable (770) is already bad enough. Change group to the webserver's group.
The better solution would be to use a database.
Greets, Felix |
|
| Back to top |
|
|
Sponsored Links
|
Posted: 5 Dec 2008 9:06 am Post subject: Advertisements |
|
|
|
|
|
|
| Back to top |
|
|