Exemple #1
0
 /**
  * @dataProvider data_sanitize
  */
 public function test_sanitize($filename, $sanitized_filename)
 {
     $this->assertEquals($sanitized_filename, Upload_Util::sanitize($filename));
 }
Exemple #2
0
 /**
  * Detirmine the filename from the url
  * @param  string $url
  * @param  string $mime_type
  * @return string
  */
 public static function filename_from_url($url, $mime_type = NULL)
 {
     $filename_candidates = Upload_Util::filenames_candidates_from_url($url);
     $filename_candidates = array_filter($filename_candidates, 'Upload_Util::is_filename');
     $file = count($filename_candidates) ? reset($filename_candidates) : uniqid();
     $extensions = File::exts_by_mime($mime_type);
     $extension_candiates = array(is_array($extensions) ? end($extensions) : $extensions, pathinfo($file, PATHINFO_EXTENSION), 'jpg');
     $extension_candiates = array_filter($extension_candiates);
     $extension = reset($extension_candiates);
     return Upload_Util::sanitize(pathinfo($file, PATHINFO_FILENAME)) . '.' . $extension;
 }