Skip to content

Commit

Permalink
wrap mime type lookup in exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
phirschybar committed May 26, 2016
1 parent 8240477 commit 06b1abf
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/controllers/StationFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function upload()
$file = $this->request->file('uploaded_file');
$original_file_name = $file->getClientOriginalName();
$size = $file->getSize();
$mime = $file->getMimeType();
$mime = $this->mime_for($file);
$this->mime = $mime;
$extension = $file->getClientOriginalExtension();
$path = pathinfo($original_file_name);
Expand Down Expand Up @@ -284,6 +284,20 @@ private function fetch_source($source_url, $new_path){
fclose($fp);
}

private function mime_for($file){

try { // sometimes this method simply fails even on legit files. wrapping it in an exception handler for now

$mime = $file->getMimeType();

} catch (Exception $e){

$mime = 'image';
}

return $mime;
}

private function send_to_s3($file, $s3_directory = '',$app_config, $is_orig = FALSE){

$target = $is_orig ? $s3_directory."/".$file : $s3_directory."/".substr($file,1);
Expand Down

0 comments on commit 06b1abf

Please sign in to comment.