editing files

  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 20th, 2004, 10:14 pm

i have these 2 scripts for editing files,

PHP Code: [ Download ] [ Select ]
<?
 
$file = $_GET['file'];
 
if($file) {
 
echo("
 
<center>
 
<form name='edit' method='get' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
 
<table width='82%' height='176' border='1'>
 
 <tr>
 
   <td height='134'>
 
<textarea name='buffer' cols='100' rows='20'>
 
");
 
$handle = fopen("page/$file", "a+");
 
while (!feof($handle)) {
 
$buffer = fgets($handle, 4096);
 
echo("$buffer");
 
 
 
}
 
 
 
echo("</textarea>");
 
fclose($handle);
 
 
 
echo("
 
   </td>
 
 </tr>
 
 <tr>
 
   <td height='36'><input name='backup' type='checkbox' value='1' checked>
 
       Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
 
       <input type='submit' name='Submit' value='Submit'>
 
       <input type='reset' name='Reset' value='Reset'>
 
   </td>
 
 </tr>
 
</table>
 
</form>
 
</center>
 
");
 
}
 
?>
  1. <?
  2.  
  3. $file = $_GET['file'];
  4.  
  5. if($file) {
  6.  
  7. echo("
  8.  
  9. <center>
  10.  
  11. <form name='edit' method='get' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
  12.  
  13. <table width='82%' height='176' border='1'>
  14.  
  15.  <tr>
  16.  
  17.    <td height='134'>
  18.  
  19. <textarea name='buffer' cols='100' rows='20'>
  20.  
  21. ");
  22.  
  23. $handle = fopen("page/$file", "a+");
  24.  
  25. while (!feof($handle)) {
  26.  
  27. $buffer = fgets($handle, 4096);
  28.  
  29. echo("$buffer");
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37. echo("</textarea>");
  38.  
  39. fclose($handle);
  40.  
  41.  
  42.  
  43. echo("
  44.  
  45.    </td>
  46.  
  47.  </tr>
  48.  
  49.  <tr>
  50.  
  51.    <td height='36'><input name='backup' type='checkbox' value='1' checked>
  52.  
  53.        Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
  54.  
  55.        <input type='submit' name='Submit' value='Submit'>
  56.  
  57.        <input type='reset' name='Reset' value='Reset'>
  58.  
  59.    </td>
  60.  
  61.  </tr>
  62.  
  63. </table>
  64.  
  65. </form>
  66.  
  67. </center>
  68.  
  69. ");
  70.  
  71. }
  72.  
  73. ?>



PHP Code: [ Download ] [ Select ]
<?
 
$file = $_GET['file'];
 
$buffer = $_GET['buffer'];
 
$backup = $_GET['backup'];
 
 
 
$handle = fopen("page/$file", "a");
 
fwrite($handle, $buffer);
 
fclose($handle);
 
 
 
if($backup == 1) {
 
$handle = fopen("page/backup/$file", "a");
 
fwrite($handle, $buffer);
 
fclose($handle);
 
}
 
?>
  1. <?
  2.  
  3. $file = $_GET['file'];
  4.  
  5. $buffer = $_GET['buffer'];
  6.  
  7. $backup = $_GET['backup'];
  8.  
  9.  
  10.  
  11. $handle = fopen("page/$file", "a");
  12.  
  13. fwrite($handle, $buffer);
  14.  
  15. fclose($handle);
  16.  
  17.  
  18.  
  19. if($backup == 1) {
  20.  
  21. $handle = fopen("page/backup/$file", "a");
  22.  
  23. fwrite($handle, $buffer);
  24.  
  25. fclose($handle);
  26.  
  27. }
  28.  
  29. ?>


But they dont work on the web, But they do work on my computer. Anyone know whats wrong with them?
College Taught Me - And we're not talking about the classes!
@travisperson
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 20th, 2004, 10:14 pm

  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 21st, 2004, 12:06 am

What are the error messages (if any)
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 10:43 am

well there are no errors it just wont even work.

http://theloshas.com/editFile.php?file=body.new.inc

from the looks of it, the the script goes to here

PHP Code: [ Download ] [ Select ]
<?
 
$file = $_GET['file'];
 
if($file) {
 
echo("
 
<center>
 
<form name='edit' method='get' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
 
<table width='82%' height='176' border='1'>
 
 <tr>
 
   <td height='134'>
 
<textarea name='buffer' cols='100' rows='20'>
 
");
  1. <?
  2.  
  3. $file = $_GET['file'];
  4.  
  5. if($file) {
  6.  
  7. echo("
  8.  
  9. <center>
  10.  
  11. <form name='edit' method='get' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
  12.  
  13. <table width='82%' height='176' border='1'>
  14.  
  15.  <tr>
  16.  
  17.    <td height='134'>
  18.  
  19. <textarea name='buffer' cols='100' rows='20'>
  20.  
  21. ");


and then it stops loading any info, or just does a continues loop.
College Taught Me - And we're not talking about the classes!
@travisperson
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 21st, 2004, 11:21 pm

This is the error I got
Code: [ Download ] [ Select ]
Warning: fopen(page/): failed to open stream: Is a directory in /home/loshas/public_html/writeFile.php on line 6

Warning: fwrite(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 7

Warning: fclose(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 8
  1. Warning: fopen(page/): failed to open stream: Is a directory in /home/loshas/public_html/writeFile.php on line 6
  2. Warning: fwrite(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 7
  3. Warning: fclose(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 8
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 11:27 pm

thats because that file got deteted and does exists, and it doesnt have to load it, so it lets do submit.
http://theloshas.com/editFile.php?file=body.inc
compared to
http://theloshas.com/editFile.php?file=blah.inc

(blah ist a real file, body.inc is)
College Taught Me - And we're not talking about the classes!
@travisperson
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 21st, 2004, 11:36 pm

Change the method in your form to post, not get
Code: [ Download ] [ Select ]
<form name='edit' method='post' action='writeFile.php?file=blah.inc&backup=&buffer='>


still get the same errors
Code: [ Download ] [ Select ]
Warning: fopen(page/): failed to open stream: Is a directory in /home/loshas/public_html/writeFile.php on line 6

Warning: fwrite(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 7

Warning: fclose(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 8
  1. Warning: fopen(page/): failed to open stream: Is a directory in /home/loshas/public_html/writeFile.php on line 6
  2. Warning: fwrite(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 7
  3. Warning: fclose(): supplied argument is not a valid stream resource in /home/loshas/public_html/writeFile.php on line 8
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 11:38 pm

the reason why those errors are they is because no info was sent to the page so it cant exicute that. so it errors it
College Taught Me - And we're not talking about the classes!
@travisperson
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 11:43 pm

editFIle.php

PHP Code: [ Download ] [ Select ]
<?
 
$file = $_POST['file'];
 
if($file) {
 
echo("
 
<center>
 
<form name='edit' method='post' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
 
<table width='82%' height='176' border='1'>
 
 <tr>
 
   <td height='134'>
 
<textarea name='buffer' cols='100' rows='20'>
 
");
 
$handle = fopen("page/$file", "a+");
 
while (!feof($handle)) {
 
$buffer = fgets($handle, 4096);
 
echo("$buffer");
 
 
 
}
 
 
 
echo("</textarea>");
 
fclose($handle);
 
 
 
echo("
 
   </td>
 
 </tr>
 
 <tr>
 
   <td height='36'><input name='backup' type='checkbox' value='1' checked>
 
       Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
 
       <input type='submit' name='Submit' value='Submit'>
 
       <input type='reset' name='Reset' value='Reset'>
 
   </td>
 
 </tr>
 
</table>
 
</form>
 
</center>
 
");
 
}
 
?>
  1. <?
  2.  
  3. $file = $_POST['file'];
  4.  
  5. if($file) {
  6.  
  7. echo("
  8.  
  9. <center>
  10.  
  11. <form name='edit' method='post' action='writeFile.php?file=$file&backup=$backup&buffer=$buffer'>
  12.  
  13. <table width='82%' height='176' border='1'>
  14.  
  15.  <tr>
  16.  
  17.    <td height='134'>
  18.  
  19. <textarea name='buffer' cols='100' rows='20'>
  20.  
  21. ");
  22.  
  23. $handle = fopen("page/$file", "a+");
  24.  
  25. while (!feof($handle)) {
  26.  
  27. $buffer = fgets($handle, 4096);
  28.  
  29. echo("$buffer");
  30.  
  31.  
  32.  
  33. }
  34.  
  35.  
  36.  
  37. echo("</textarea>");
  38.  
  39. fclose($handle);
  40.  
  41.  
  42.  
  43. echo("
  44.  
  45.    </td>
  46.  
  47.  </tr>
  48.  
  49.  <tr>
  50.  
  51.    <td height='36'><input name='backup' type='checkbox' value='1' checked>
  52.  
  53.        Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
  54.  
  55.        <input type='submit' name='Submit' value='Submit'>
  56.  
  57.        <input type='reset' name='Reset' value='Reset'>
  58.  
  59.    </td>
  60.  
  61.  </tr>
  62.  
  63. </table>
  64.  
  65. </form>
  66.  
  67. </center>
  68.  
  69. ");
  70.  
  71. }
  72.  
  73. ?>


Now it wont even run the script at all it says that $file is not existing by just showing

Code: [ Download ] [ Select ]
<html><body></body></html>
College Taught Me - And we're not talking about the classes!
@travisperson
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 11:50 pm

to fix those erros your getting there fixed now.

if you use the link
http://theloshas.com/writeFile.php?file ... mit=Submit
College Taught Me - And we're not talking about the classes!
@travisperson
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 21st, 2004, 11:54 pm

Why are you outputting the text area to the url? take that variable away, it is just going to cause problems
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 21st, 2004, 11:58 pm

Not to be mean or anything but can you help with getting my editFile,php page to work, so the file will load in the page so i can see whats in it? then i can go from there and get othe things to work or ask for more help.
College Taught Me - And we're not talking about the classes!
@travisperson
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 22nd, 2004, 12:10 am

Dude I don't know what the issue is. You tell me it works on one machine and not the other.

Is your box a linux or windows box?
is the server a windows or linux box?
What version is the PHP that it works on?
What version is the PHP that it doesn't work on?

If you want people to help you need to supply the correct info, otherwise you end up with what happened now. People going backwards and forwards trying to guess the problem.

The only conclusion I can come to is that there is a config problem on one of the machines. If it works on one and not the other is not the script.
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 22nd, 2004, 12:18 am

my Machine is Window XP Pro; php V 4.3.3
my Server is Linux redhat; php V 4.3.9

Im sorry for not sapline the info before hand i didnt think you needed it and if you did you would of asked.

I dont quite get why it doesnt work becasue its jsut a simple script, and i got it all off of the php webpage so im wondering why it doesnt work for the latest verions vs the older one.

i was rushed posting this info because my internet would work for 5 minutes then shut off for 5 hours and then work again for maybe 5 minutes. Now its working better so maybe we can figger it out.
College Taught Me - And we're not talking about the classes!
@travisperson
  • Rabid Dog
  • Cheese Monkey
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3188
  • Loc: South Africa
  • Status: Offline

Post December 22nd, 2004, 12:28 am

Okay so we are going to focus on getting the info into the text browser
okay replace the lines
PHP Code: [ Download ] [ Select ]
 
$handle = fopen("page/$file", "a+");
 
while (!feof($handle)) {
 
$buffer = fgets($handle, 4096);
 
echo("$buffer");
 
 
 
 
  1.  
  2. $handle = fopen("page/$file", "a+");
  3.  
  4. while (!feof($handle)) {
  5.  
  6. $buffer = fgets($handle, 4096);
  7.  
  8. echo("$buffer");
  9.  
  10.  
  11.  
  12.  

with
PHP Code: [ Download ] [ Select ]
 
$path = "page/" . $file;
 
echo $file; //do this to check the file name etc
 
$buffer = file_get_contents("page/$file", "r");
 
echo("$buffer");
 
 
  1.  
  2. $path = "page/" . $file;
  3.  
  4. echo $file; //do this to check the file name etc
  5.  
  6. $buffer = file_get_contents("page/$file", "r");
  7.  
  8. echo("$buffer");
  9.  
  10.  


and delete the line that has
PHP Code: [ Download ] [ Select ]
 
fclose($handle);
 
 
  1.  
  2. fclose($handle);
  3.  
  4.  
My Software Development Company
Music I have recorded (fixed now :))
Image
  • SpooF
  • Ice Cream
  • Bronze Member
  • User avatar
  • Joined: May 22, 2004
  • Posts: 2826
  • Loc: Richland, WA
  • Status: Offline

Post December 22nd, 2004, 12:42 am

Alright now were getting someplace, THANK YOU SO MUCH for saying with me on this and helping.

http://theloshas.com/edit.php?file=body.news.inc

now tell me if the top part should be get or post beacuse if you use post it doesnt work but if you use get it dose

PHP Code: [ Download ] [ Select ]
<?
 
$file = $_GET['file'];
 
 
 
echo("
 
<center>
 
<form name='edit' method='post' action='writeFile.php'>
 
<table width='82%' height='176' border='1'>
 
 <tr>
 
   <td height='134'>
 
<textarea name='buffer' cols='100' rows='20'>
 
");
 
$path = "page/" . $file;
 
echo $file; //do this to check the file name etc
 
$buffer = file_get_contents("page/$file", "r");
 
echo("$buffer");
 
 
 
 
 
echo("</textarea>");
 
 
 
 
 
echo("
 
   </td>
 
 </tr>
 
 <tr>
 
   <td height='36'><input name='backup' type='checkbox' value='1' checked>
 
       Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
 
       <input type='submit' name='Submit' value='Submit'>
 
       <input type='reset' name='Reset' value='Reset'>
 
   </td>
 
 </tr>
 
</table>
 
</form>
 
</center>
 
");
 
 
 
?>
  1. <?
  2.  
  3. $file = $_GET['file'];
  4.  
  5.  
  6.  
  7. echo("
  8.  
  9. <center>
  10.  
  11. <form name='edit' method='post' action='writeFile.php'>
  12.  
  13. <table width='82%' height='176' border='1'>
  14.  
  15.  <tr>
  16.  
  17.    <td height='134'>
  18.  
  19. <textarea name='buffer' cols='100' rows='20'>
  20.  
  21. ");
  22.  
  23. $path = "page/" . $file;
  24.  
  25. echo $file; //do this to check the file name etc
  26.  
  27. $buffer = file_get_contents("page/$file", "r");
  28.  
  29. echo("$buffer");
  30.  
  31.  
  32.  
  33.  
  34.  
  35. echo("</textarea>");
  36.  
  37.  
  38.  
  39.  
  40.  
  41. echo("
  42.  
  43.    </td>
  44.  
  45.  </tr>
  46.  
  47.  <tr>
  48.  
  49.    <td height='36'><input name='backup' type='checkbox' value='1' checked>
  50.  
  51.        Create Backup &nbsp;&nbsp;&nbsp;:: &nbsp;&nbsp;&nbsp;
  52.  
  53.        <input type='submit' name='Submit' value='Submit'>
  54.  
  55.        <input type='reset' name='Reset' value='Reset'>
  56.  
  57.    </td>
  58.  
  59.  </tr>
  60.  
  61. </table>
  62.  
  63. </form>
  64.  
  65. </center>
  66.  
  67. ");
  68.  
  69.  
  70.  
  71. ?>
College Taught Me - And we're not talking about the classes!
@travisperson
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post December 22nd, 2004, 12:42 am

Post Information

  • Total Posts in this topic: 25 posts
  • Users browsing this forum: cleartango, planetsap and 416 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© Unmelted Enterprises 1998-2009. Driven by phpBB © 2001-2009 phpBB Group.