Skip to content

Instantly share code, notes, and snippets.

@tylerhall
Created January 3, 2011 21:36
Show Gist options
  • Save tylerhall/764010 to your computer and use it in GitHub Desktop.
Save tylerhall/764010 to your computer and use it in GitHub Desktop.
<?PHP
$files = scandir(DOC_ROOT . IMG_PATH);
foreach($files as $fn)
{
if(!in_array(substr($fn, -3), array('jpg', 'png', 'gif'))) continue;
$object = IMG_PATH . $fn;
$the_file = DOC_ROOT . IMG_PATH . $fn;
// Only upload if the file is different
if(!$s3->objectIsSame($bucket, $object, md5_file($the_file)))
{
echo "Putting $the_file . . . ";
if($s3->putObject($bucket, $object, $the_file, true, null, array('Expires' => $expires)))
echo "OK\n";
else
echo "ERROR!\n";
}
else
echo "Skipping $the_file\n";
}
<?PHP
$gz = strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== false ? 'gz.' : '';
<link rel="stylesheet" href="http://cdn.tyler.fm/css/main.<?PHP echo $gz;?>css" type="text/css">
<?PHP
// List your stylesheets here for concatenation...
$css = file_get_contents(DOC_ROOT . CSS_PATH . 'reset-fonts-grids.css') . "\n\n";
$css .= file_get_contents(DOC_ROOT . CSS_PATH . 'screen.css') . "\n\n";
$css .= file_get_contents(DOC_ROOT . CSS_PATH . 'jquery.lightbox.css') . "\n\n";
$css .= file_get_contents(DOC_ROOT . CSS_PATH . 'syntax.css') . "\n\n";
file_put_contents(DOC_ROOT . CSS_PATH . 'combined.css', $css);
shell_exec('gzip -c ' . DOC_ROOT . CSS_PATH . 'combined.css > ' . DOC_ROOT . CSS_PATH . 'combined.gz.css');
if(!$s3->objectIsSame($bucket, CSS_PATH . 'combined.css', md5_file(DOC_ROOT . CSS_PATH . 'combined.css')))
{
echo "Putting combined.css...";
if($s3->putObject($bucket, CSS_PATH . 'combined.css', DOC_ROOT . CSS_PATH . 'combined.css', true, null, array('Expires' => $expires)))
echo "OK\n";
else
echo "ERROR!\n";
echo "Putting combined.gz.css...";
if($s3->putObject($bucket, CSS_PATH . 'combined.gz.css', DOC_ROOT . CSS_PATH . '/combined.gz.css', true, null, array('Expires' => $expires, 'Content-Encoding' => 'gzip')))
echo "OK\n";
else
echo "ERROR!\n";
}
else
echo "Skipping combined.css\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment