[solved] editing a file online... script nearly made

  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 22nd, 2004, 12:36 pm

hi, i created most of my website which is based on css. Reason why it is based on css is so that it can be easier to change around. Layouts and images.

so here is my code at the moment.

(tbh i used a source which helped).

Code: [ Select ]
<?php

if ($submit) {
$fp = fopen("/style/style.css", "w");
fwrite($fp, stripslashes($newdata));
fclose($fp);
}

$fp = fopen("/style/style.css", "r");
while (!feof($fp)) {
$data .= fgets($fp, 4096);
}
fclose($fp);

?>

<html>
<head>
<title>Edit CSS</title>
</head>

<body>
<form action="<? print $PHP_SELF; ?>" method="post">
<textarea name="newdata" rows="10" cols="40">
<?
print $data;
?>
</textarea>

<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>
  1. <?php
  2. if ($submit) {
  3. $fp = fopen("/style/style.css", "w");
  4. fwrite($fp, stripslashes($newdata));
  5. fclose($fp);
  6. }
  7. $fp = fopen("/style/style.css", "r");
  8. while (!feof($fp)) {
  9. $data .= fgets($fp, 4096);
  10. }
  11. fclose($fp);
  12. ?>
  13. <html>
  14. <head>
  15. <title>Edit CSS</title>
  16. </head>
  17. <body>
  18. <form action="<? print $PHP_SELF; ?>" method="post">
  19. <textarea name="newdata" rows="10" cols="40">
  20. <?
  21. print $data;
  22. ?>
  23. </textarea>
  24. <input type="submit" name="submit" value="Submit">
  25. </form>
  26. </body>
  27. </html>


there seems to be an error on these 2 code lines

PHP Code: [ Select ]
 
while (!feof($fp)) {
 
$data .= fgets($fp, 4096);
 
}
  1.  
  2. while (!feof($fp)) {
  3.  
  4. $data .= fgets($fp, 4096);
  5.  
  6. }


These two lines i am not familiar with. Can someone please explain? and if there is a solution?

I change the folder permission settings so it can be uploaded.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 22nd, 2004, 12:36 pm

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

Post June 22nd, 2004, 12:56 pm

What is the error message that you get?

The two lines of code that don't make sense are opening the file and reading the contents into a variable
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:00 am

the error message says there is an error on them 2 lines i mentioned.

it keeps repeating the error and does not stop.

so it says

"lines 10 and 11" or something... then the error...
then carries on adding it without stopping
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:07 am

here is the webpage:

http://www.69kilobytes.co.uk/cp/edit.php
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post June 23rd, 2004, 3:17 am

Code: [ Select ]
Warning: fopen(): open_basedir restriction in effect. File(/css/style.css) is not within the allowed path(s): (/home/virtual/site2/fst/:/home/virtual/69kilobytes.co.uk/:/var/www/html/) in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 9


This is the error message you need to look at. It is telling you that you don't have permission to access the file. So it will fall over everytime it tries to get it

Try this.
PHP Code: [ Select ]
 
$fp = fopen("style/style.css", "w");
 
$fp = fopen("style/style.css", "r");
 
 
  1.  
  2. $fp = fopen("style/style.css", "w");
  3.  
  4. $fp = fopen("style/style.css", "r");
  5.  
  6.  


the one with the 'w' option is for the submit and the other is to get the file and read it.

Let me know if it works
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:22 am

is this how i should have it?

PHP Code: [ Select ]
 
<?php
 
 
 
if ($submit) {
 
$fp = fopen("/css/style.css", "w");
 
fwrite($fp, stripslashes($newdata));
 
fclose($fp);
 
}
 
$fp = fopen("style/style.css", "w");
 
$fp = fopen("style/style.css", "r");
 
while (!feof($fp)) {
 
$data .= fgets($fp, 4096);
 
}
 
fclose($fp);
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. if ($submit) {
  7.  
  8. $fp = fopen("/css/style.css", "w");
  9.  
  10. fwrite($fp, stripslashes($newdata));
  11.  
  12. fclose($fp);
  13.  
  14. }
  15.  
  16. $fp = fopen("style/style.css", "w");
  17.  
  18. $fp = fopen("style/style.css", "r");
  19.  
  20. while (!feof($fp)) {
  21.  
  22. $data .= fgets($fp, 4096);
  23.  
  24. }
  25.  
  26. fclose($fp);
  27.  
  28.  
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post June 23rd, 2004, 3:25 am

What directory is your style sheet in?
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:27 am

http://www.69kilobytes.co.uk/style/style.css

and i have chmodd it to 777
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post June 23rd, 2004, 3:29 am

so it should read

PHP Code: [ Select ]
 
<?php
 
 
 
if ($submit) {
 
$fp = fopen("style/style.css", "w");
 
fwrite($fp, stripslashes($newdata));
 
fclose($fp);
 
}  
 
$fp = fopen("style/style.css", "r");
 
while (!feof($fp)) {
 
$data .= fgets($fp, 4096);
 
}
 
fclose($fp);
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. if ($submit) {
  7.  
  8. $fp = fopen("style/style.css", "w");
  9.  
  10. fwrite($fp, stripslashes($newdata));
  11.  
  12. fclose($fp);
  13.  
  14. }  
  15.  
  16. $fp = fopen("style/style.css", "r");
  17.  
  18. while (!feof($fp)) {
  19.  
  20. $data .= fgets($fp, 4096);
  21.  
  22. }
  23.  
  24. fclose($fp);
  25.  
  26. ?>
  27.  
  28.  


this will open the file and write it to the same file when you submit it
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:36 am

ok, now if you go to the page:

http://www.69kilobytes.co.uk/cp/edit.php
you will see the style sheet.... but if you click submit it will say the following errors:

Quote:
Warning: fopen(http://www.69kilobytes.co.uk/style/style.css): failed to open stream: HTTP wrapper does not support writeable connections. in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 4

Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 6


i take it i need to look at:
Quote:
Warning: fopen(http://www.69kilobytes.co.uk/style/style.css): failed to open stream: HTTP wrapper does not support writeable connections. in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 4

now i chmodded the style.css file to 777 as well.

but still the same error shows. What does this mean?
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post June 23rd, 2004, 3:53 am

Okay try this

PHP Code: [ Select ]
 
<?php
 
 
 
if ($submit) {
 
$fp = fopen("style/style.css", "w+");
 
fwrite($fp, stripslashes($newdata));
 
fclose($fp);
 
}  
 
$fp = fopen("style/style.css", "r");
 
while (!feof($fp)) {
 
$data .= fgets($fp, 4096);
 
}
 
fclose($fp);
 
?>
 
 
  1.  
  2. <?php
  3.  
  4.  
  5.  
  6. if ($submit) {
  7.  
  8. $fp = fopen("style/style.css", "w+");
  9.  
  10. fwrite($fp, stripslashes($newdata));
  11.  
  12. fclose($fp);
  13.  
  14. }  
  15.  
  16. $fp = fopen("style/style.css", "r");
  17.  
  18. while (!feof($fp)) {
  19.  
  20. $data .= fgets($fp, 4096);
  21.  
  22. }
  23.  
  24. fclose($fp);
  25.  
  26. ?>
  27.  
  28.  


will explain it if it works
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 3:58 am

Quote:
Warning: fopen(http://www.69kilobytes.co.uk/style/style.css): failed to open stream: HTTP wrapper does not support writeable connections. in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 4

Warning: fwrite(): supplied argument is not a valid stream resource in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in /home/virtual/site2/fst/var/www/html/cp/edit.php on line 6


this is what shows up

if i use the directory:
Quote:
style/style.css
then it says that there is no such directory, which is why i use the full url. When i do, it shows up just fine, but when i submit this is when the error shows up on top of the text area.
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Joined: May 21, 2004
  • Posts: 3229
  • Loc: South Africa
  • Status: Offline

Post June 23rd, 2004, 4:10 am

what is your directory structure?
is edit.php in the same directory as the stylesheet?

if
http://www.domain.com/
is your root, where would the style sheet be and where would the edit.php file be?
Watch me grow
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 4:13 am

ok basically there is...

http://www.69kilobytes.co.uk

then the following folders

mainwebsite_html
mainwebsite_cgi
mainwebsite_something

the main directory is "mainWebsite_html"

so if "index.php" is in "website_html" then to access it, it would be...

http://www.69kilobytes.co.uk/index.php

this means that "mainwebsite_html" is the main directory?

so altogether.

http://www.69kilobytes.co.uk/mainwebsit ... /style.css - but this does not work

so

http://www.69kilobytes.co.uk/style/style.css


Ps. this message was edited
  • Nem
  • Guru
  • Guru
  • No Avatar
  • Joined: Feb 13, 2004
  • Posts: 1243
  • Loc: UK
  • Status: Offline

Post June 23rd, 2004, 4:15 am

here: http://www.69kilobytes.co.uk/style/style.css


you see, it will download the css file
GSDomains.com -Click here - Packages starting from £3.69 a month. 1.5GB Space & 10GB Bandwidth.
  • Anonymous
  • Bot
  • No Avatar
  • Joined: 25 Feb 2008
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post June 23rd, 2004, 4:15 am

Post Information

  • Total Posts in this topic: 24 posts
  • Users browsing this forum: No registered users and 275 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
 
 

© 2011 Unmelted, LLC. Ozzu® is a registered trademark of Unmelted, LLC.