mirror of
https://github.com/mrclay/minify.git
synced 2025-02-23 08:25:12 +01:00
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?php
|
|
|
|
if (isset($_FILES['subject']['name'])
|
|
&& preg_match('/\\.(js|css|x?html?)$/', $_FILES['subject']['name'], $m)
|
|
) {
|
|
require '../config.php';
|
|
|
|
// easier to just require them all
|
|
require 'Minify/HTML.php';
|
|
require 'Minify/CSS.php';
|
|
require 'Minify/Javascript.php';
|
|
|
|
$arg2 = null;
|
|
switch ($m[1]) {
|
|
case 'js':
|
|
$type = 'Javascript';
|
|
break;
|
|
case 'css':
|
|
$type = 'CSS';
|
|
break;
|
|
case 'html': // fallthrough
|
|
case 'htm': // fallthrough
|
|
case 'xhtml':
|
|
$type = 'HTML';
|
|
$arg2 = array(
|
|
'cssMinifier' => array('Minify_CSS', 'minify')
|
|
,'jsMinifier' => array('Minify_Javascript', 'minify')
|
|
);
|
|
}
|
|
$func = array('Minify_' . $type, 'minify');
|
|
|
|
$out = call_user_func($func, file_get_contents($_FILES['subject']['tmp_name']), $arg2);
|
|
|
|
header('Content-Type: application/octet-stream');
|
|
header('Content-Transfer-Encoding: binary');
|
|
header('Content-Disposition: attachment; filename="'
|
|
. preg_replace('/\\.(\w+)$/', '.min.$1', $_FILES['subject']['name'])
|
|
. '"');
|
|
|
|
//@unlink($_FILES['subject']['tmp_name']);
|
|
echo $out;
|
|
exit();
|
|
}
|
|
|
|
?>
|
|
<form enctype="multipart/form-data" action="" method="post">
|
|
<p>Minify <input type="file" name="subject" /><br />
|
|
<input type="submit" name="method" value="Go!" />
|
|
</p>
|
|
</form>
|