2

My project is in PHP, I need change the image folder name in css files dynamically,

ie.,

# all.css file

.html{
background: url(../img/login.gif) no-repeat scroll 0 -36px;
.....
}

I need change the folder name "img" to "image" or "styleimg" etc., depends on the templatewise. How is it possible with the php file ?

0

2 Answers 2

2

Use PHP to serve out the CSS. Use the header() to set the content type as text/css, output most of the CSS outside of the tag (but after setting the header of course). Find out the selected template in this PHP, assign the required directory name to a variable, say, $imgloc.

Then, at the lines where you require to output the image name, do something like this:

background: url(../<?= $imgloc ?>/login.gif) no-repeat scroll 0 -36px;
Sign up to request clarification or add additional context in comments.

1 Comment

Raze, we need do to with external stylesheet only.
0
<?php
$file = xyz.css;
$handle = @fopen($file, "r"); // Open file form read.

$line_match = "background: url(../img/login.gif) no-repeat scroll 0 -36px;\n";

$toThis = "background: url(../img/new_login_image.gif) no-repeat scroll 0 -36px;\n";

if ($handle) {
while (!feof($handle)) // Loop til end of file.
{
$buffer .= fgets($handle, 4096); // Read a line.
if ($buffer == $line_match) // Check for string.
{
echo "$buffer"; // If not string show contents.
} else {
$buffer .= $toThis; // If string, change it.
echo "$buffer"; // and show changed contents.
}
}

$Handle = fopen($file, 'w');
$Data = $buffer; 
fwrite($Handle, $Data); 


fclose($handle); // Close the file.
}

?>

maybe drop the \n im from vars $linematch and $toThis not sure off hand! - try both.

1 Comment

Hi cocacola09, This will rewrite the css file. I need change the image folder name dynamically (by ussing variable or any other method ), depends on the member choose red,green or etc template color. 100 more members are login at a time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.