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

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

here is the webpage:

http://www.69kilobytes.co.uk/cp/edit.php
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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.  
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

What directory is your style sheet in?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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

and i have chmodd it to 777
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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?
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

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?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

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


you see, it will download the css file
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay what directory is the edit.php file in?
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

http://www.69kilobytes.co.uk/cp/edit.php
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Okay try this, I think I have figured it out but let me know if it works and I'll explain what happened
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.  
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

oh man you the best lol.

i look up to you now.... got to learn hardcore php
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

what is a parse error? im tryign to add a header to it.

<? include="filename" ?> that is correct?

or if i put it underneath the ?php

then

include="filename";
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

let me fix this one.... :P
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Nem wrote:
oh man you the best lol.

i look up to you now.... got to learn hardcore php


That was just a logic problem. we need to tell the script to get out of the cp folder and look for the style folder
hence the ../ before the style/style.css

A parse error means there is something wrong with your syntax. I need to see the error and then the code you are using to tell you where you are going wrong
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

i have done it... most of my problems been solved by you.

Thank you very much.
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

was a pleasure.

Enjoy!

Post Information

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

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.