Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-30-2006, 07:31 PM   PM User | #1
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
Creating an editable style sheet

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,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-30-2006, 07:46 PM   PM User | #2
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
PHP Code:
<?php
$file 
$_GET['file'];
$css file_get_contents($file);
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<textarea name="css"><?php echo $css?></textarea>
<input type="hidden" name="file" value="<?php echo $file?>" />
<input type="submit" />
</form>
<?php
if (isset($_POST['css']) && isset($_POST['file'])){
$file $_POST['file'];
$css $_POST['css'];
$f_handle fopen($file'w+');
fwrite($f_handle$css);
}
?>
Mwnciau is offline   Reply With Quote
Old 08-30-2006, 08:01 PM   PM User | #3
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
Thanks for the quick reply, but when I run the script, I get an error on the line:
PHP Code:
fwrite($f_handle$css); 
Can you help?
Also, where do I put the path to the file and can I put it as an URL or do I have to use a server path?
Thanks,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-30-2006, 08:14 PM   PM User | #4
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
PHP Code:
<?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.
GJay is offline   Reply With Quote
Old 08-30-2006, 08:20 PM   PM User | #5
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
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,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-30-2006, 08:23 PM   PM User | #6
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
as my example showed, it needs to be a file-system location, not a url.
GJay is offline   Reply With Quote
Old 08-30-2006, 08:26 PM   PM User | #7
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
This is a really stupid question:
How do I get to the public_html directory with a filesystem?
Thanks,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-30-2006, 08:58 PM   PM User | #8
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
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,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-30-2006, 08:59 PM   PM User | #9
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
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...
GJay is offline   Reply With Quote
Old 08-30-2006, 08:59 PM   PM User | #10
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
without giving the errors, it's really difficult to help...
GJay is offline   Reply With Quote
Old 08-31-2006, 09:14 AM   PM User | #11
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
The error is:
Fatal error: Call to undefined function: () in /home/ttttt/public_html/admin/css/editcss.php on line 30
Thanks,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-31-2006, 09:43 AM   PM User | #12
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
The thought suddenly dawned on me, I'm only using PHP 4. Does this make a difference when fdealing with the errors?
Thanks,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software
ttttt is offline   Reply With Quote
Old 08-31-2006, 11:21 AM   PM User | #13
Lee Stevens
Regular Coder

 
Join Date: Aug 2006
Location: UK, London, Dartford
Posts: 221
Thanks: 3
Thanked 14 Times in 14 Posts
Lee Stevens is an unknown quantity at this point
Have you chnaged the permissions? to 777?
Lee Stevens is offline   Reply With Quote
Old 08-31-2006, 12:38 PM   PM User | #14
GJay
Senior Coder

 
Join Date: Sep 2005
Posts: 1,791
Thanks: 5
Thanked 36 Times in 35 Posts
GJay is on a distinguished road
typo on my part,
PHP Code:
$fwrite($fp,$_POST['css']);  //write the contents 
should have been
PHP Code:
fwrite($fp,$_POST['css']);  //write the contents 
GJay is offline   Reply With Quote
Old 08-31-2006, 04:31 PM   PM User | #15
ttttt
Regular Coder

 
ttttt's Avatar
 
Join Date: Oct 2005
Posts: 372
Thanks: 0
Thanked 0 Times in 0 Posts
ttttt is an unknown quantity at this point
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>
Thanks,
__________________
ttttt
http://openoffice.org/- Microsoft Office without the Microsoft.
[home page][forum]
Versatile, free software

Last edited by ttttt; 08-31-2006 at 05:46 PM..
ttttt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:29 AM.


Advertisement
Log in to turn off these ads.