Jump to content

[SOLVED] Using PHP to write to external .css pages


webent

Recommended Posts

Hi, I was wondering if someone could tell me what I'm doing wrong or if there is a better way to go about achieving my desired goal...

 

I'm trying to allow users to modify external .css pages... They select the desired style sheet from a dropdown that has all of the css files in that directory, it opens the style sheet using fopen and fread, places the content in a form textarea... This all works great up to this point, but when they make changes, they don't save... So my first thought was to check CHMOD to make sure that they were in fact still changed to 666, they were, so I tried 777, still no go...

 

Here's my code thus far...

$myFile = "style-sheet.css";  //example
$fh = fopen($myFile, 'r');

if (isset($_POST['submitChanges'])) {
$stringData = $_POST['newSheet'];
fwrite($fh, $stringData);    
}
                            
$theData = fread($fh, filesize($myFile));
echo '<form action="' . $_SERVER['php_self'] . '" method="post">
<textarea name="newSheet" cols="100" rows="100">' . $theData . '</textarea>
<input type="submit" name="submitChanges" value="Submit Changes">
</form>'; 

fclose($fh); 

Link to comment
Share on other sites

Ok, I got it... stupid mistake on my part, I needed to changed fopen to write in the write part of the code...

 

here's the final code...

if (isset($_POST['submitChanges'])) {
$myFile = "style-sheet.css";  
$fh = fopen($myFile, 'w');    
$stringData = $_POST['newSheet'];   
fwrite($fh, $stringData);
fclose($fh);    
}

$myFile = "style-sheet.css";
$fh = fopen($myFile, 'r');                                                     
$theData = fread($fh, filesize($myFile));
echo '<form action="' . $_SERVER['php_self'] . '" method="post">
<textarea name="newSheet" cols="100" rows="100">' . $theData . '</textarea>
<input type="submit" name="submitChanges" value="Submit Changes">
</form>'; 
fclose($fh); 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.