function live_css_save in Live CSS 7
Same name and namespace in other branches
- 6.2 live_css.module \live_css_save()
- 6 live_css.module \live_css_save()
- 7.2 live_css.module \live_css_save()
1 string reference to 'live_css_save'
- live_css_menu in ./
live_css.module - Implements hook_menu().
File
- ./
live_css.module, line 125
Code
function live_css_save() {
$css = $_POST['css'];
$href = $_POST['href'];
//calculate the file path relative to the base drupal folder
$parts = split('/', $href);
$path = '';
for ($i = 3; $i < count($parts); $i++) {
$path .= $parts[$i] . '/';
}
if (strpos($path, '?') > 0) {
$path = substr($path, 0, strpos($path, '?'));
}
else {
$path = substr($path, 0, -1);
}
$path = $_SERVER['DOCUMENT_ROOT'] . '/' . $path;
//save file back
$fh = fopen($path, 'w') or die("Can't open file " . $path . " at " . $href);
fwrite($fh, $css);
fclose($fh);
echo drupal_json_encode(array(
'result' => 'success',
'filename' => $path,
));
}