Skip to content

Instantly share code, notes, and snippets.

@miklschmidt
Created May 8, 2012 22:08
Show Gist options
  • Save miklschmidt/2639799 to your computer and use it in GitHub Desktop.
Save miklschmidt/2639799 to your computer and use it in GitHub Desktop.
<?php
$css = $_GET['path'];
$less = str_replace(".css",".less",$css);
file_exists($less) and $compiled_css = str_replace(".css", filemtime($less) . ".css", $_GET['path']);
if (!empty($compiled_css) and !file_exists($compiled_css))
{
header("Content-type: text/css");
$less_command = "/var/www/node/node_modules/less/bin/lessc ".realpath($less)." ".realpath($compiled_css);
shell_exec($less_command);
}
if (file_exists($compiled_css))
{
header("Content-type: text/css");
$css_file = file_get_contents($compiled_css);
echo $css_file;
}
else
{
# Just in case you haven't configured your error levels appropriately in you production env.
ob_start();
trigger_error("couldn't find/compile $less");
ob_end_clean();
header("HTTP/1.0 404 Not Found");
echo "Not Found";
}
@miklschmidt
Copy link
Author

Not tested.. should work though

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment