Beautify the title of uploaded files. Convert underscores to spaces, collapse multiple spaces, drop the extension. Fixes ticket #237

This commit is contained in:
Bharat Mediratta
2009-05-13 02:52:09 +00:00
parent 99c26f30c6
commit ee4f9eaa00

View File

@@ -48,6 +48,7 @@ class Simple_Uploader_Controller extends Controller {
$temp_filename = upload::save("Filedata");
try {
$title = substr(basename($temp_filename), 10); // Skip unique identifier Kohana adds
$title = $this->convert_filename_to_title($title);
$path_info = pathinfo($temp_filename);
if (array_key_exists("extension", $path_info) &&
in_array(strtolower($path_info["extension"]), array("flv", "mp4"))) {
@@ -68,6 +69,16 @@ class Simple_Uploader_Controller extends Controller {
print "File Received";
}
/**
* We should move this into a helper somewhere.. but where is appropriate?
*/
private function convert_filename_to_title($filename) {
$title = strtr($filename, "_", " ");
$title = preg_replace("/\..*?$/", "", $title);
$title = preg_replace("/ +/", " ", $title);
return $title;
}
public function finish() {
batch::stop();
print json_encode(array("result" => "success"));