Hi,
I'm trying to create a script that opens a css style sheet and inside a form field, inserts the data from the style sheet, so that it can be edited as a whole. I'm also trying to have a submit button that writes the whole thing back to the file.
I know to open the file, I need to use fopen(), but that's about as far as my knowledge spreads. And I also know that the script isn't unique to a css stly sheet but could be used for any file.
I would appreciate some help with my problem greatly,
Thanks,
<?php
//you know where the CSS is, so no need to let the user choose the file
$file='/var/www/mysite/css/style.css';
//perhaps confusingly, deal with the submission first
if(isset($_POST['the_css'])) {
$fp=fopen($file,'w+'); //open the file for *w*riting
$fwrite($fp,$_POST['css']); //write the contents
fclose($fp); //remember to close the file
}
//to display the form
$css=file_get_contents($file); //read in the file contents
//no need for php to get in the way for a while...
?>
<form action="" method="post">
<textarea rows="10" cols="40" name="the_css">
<?php echo $css; ?>
</textarea>
<input type="submit" value="Submit" />
</form>
the file specified in $file must be writable by the web-server.
Accepting the file location from the user, is a really really stupid thing to do.
Remember though, that people could put things in the CSS that you might not want them to.
I still get this error:
Warning: fopen(http://versa-soft.com/css.css) [function.fopen]: failed to open stream: HTTP wrapper does not support writeable connections. in
public_html/admin/css/editcss.php on line 29
Fatal error: Call to undefined function: () in public_html/admin/css/editcss.php on line 30
This error appears when the page is submitted. The inclusion of the css file works fine though.
Thanks for the help,
Ok, I've found out the last question, but I still get errors. I've totally changed the file permissions and I tried ignoring the errors, but then it totally wipes my style sheet.
Thanks for all of the help,
it depends.
typically, you'll have:
/home/ttttt/public_html
(where ttttt is the username you log in with).
typing 'pwd' at a command line will tell you...think this will work with ftp as well as shell access.
if you're using a gui ftp client, then there must be some way of determining the current directory...
It still doesn't work.
No PHP errors appear, but it doesn't write the style sheet, it doesn't wipe totally.
So far, I am using this code:
PHP Code:
<?php //you know where the CSS is, so no need to let the user choose the file $file='/home/ttttt/public_html/css.css';
//perhaps confusingly, deal with the submission first if(isset($_POST['the_css'])) { $fp=fopen($file, 'a+'); //open the file for *w*riting fwrite($fp,$_POST['the_css']); //write the contents fclose($fp); //remember to close the file }
//to display the form $css=file_get_contents($file); //read in the file contents
//no need for php to get in the way for a while... ?> <form action="" method="post"> <textarea rows="10" cols="40" name="the_css"> <?php echo $css; ?> </textarea> <input type="submit" value="Submit" /> </form> </p>