Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function globistr($string = '', $mbEncoding = ''/*optional e.g.'UTF-8'*/)
- {
- //returns a case insensitive Version of the searchPattern for glob();
- // e.g.: globistr('./*.jpg') => './*.[jJ][pP][gG]'
- // e.g.: glob(dirname(__FILE__).'/'.globistr('*.jpg')) => '/.../*.[jJ][pP][gG]'
- // known problems: globistr('./[abc].jpg') => FALSE:'./[[aA][bB][cC]].[jJ][pP][gG]'
- //(Problem: existing Pattern[abc] will be overwritten)
- // known solution: './[abc].'.globistr('jpg') => RIGHT: './[abc].[jJ][pP][gG]'
- //(Solution: globistr() only caseSensitive Part, not everything)
- $return = "";
- if($mbEncoding !== ''){ //multiByte Version
- $string = mb_convert_case($string,MB_CASE_LOWER,$mbEncoding);
- }
- else{ //standard Version (not multiByte,default)
- $string = strtolower($string);
- }
- $mystrlen = strlen($string);
- for($i=0;$i<$mystrlen;$i++){
- if($mbEncoding !== ''){//multiByte Version
- $myChar = mb_substr($string,$i,1,$mbEncoding);
- //$myUpperChar = mb_strtoupper($myChar,$mbEncoding);
- $myUpperChar = mb_convert_case($myChar,MB_CASE_UPPER,$mbEncoding);
- }else{
- $myChar = substr($string,$i,1);
- $myUpperChar = strtoupper($myChar);
- }
- if($myUpperChar !== $myChar){ //there is a lower- and upperChar, / Char is case sentitive
- $return .= '['.$myChar.$myUpperChar.']'; //adding both Versions : [xX]
- }else{//only one case Version / Char is case insentitive
- $return .= $myChar; //adding '1','.','*',...
- }
- }
- return $return;
- }
- if ( ! function_exists('glob_recursive'))
- {
- // Does not support flag GLOB_BRACE
- function glob_recursive($pattern, $flags = 0)
- {
- $files = glob($pattern, $flags);
- foreach (glob(dirname($pattern).'\*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir)
- {
- $files = array_merge($files, glob_recursive($dir.'\\'.basename($pattern), $flags));
- }
- return $files;
- }
- }
- function glob_files($filenames, $source_folder)
- {
- if( !is_dir( $source_folder ) ) {
- die ( "Invalid directory.\n\n" );
- }
- $filenames = explode(' ', $filenames);
- $formats = array('mp4', 'avi', 'mkv');
- $key = 0;
- foreach ($filenames as $filename):
- foreach ($formats as $format):
- $FILES = glob_recursive($source_folder."\*".globistr($filename)."*.".$format);
- foreach($FILES as $file) {
- $FILE_LIST[$key]['path'] = substr( $file, 0, ( strrpos( $file, "\\" ) +1 ) );
- $FILE_LIST[$key]['name'] = substr( $file, ( strrpos( $file, "\\" ) +1 ) );
- $FILE_LIST[$key]['size'] = filesize( $file );
- $FILE_LIST[$key]['date'] = date('Y-m-d G:i:s', filemtime( $file ) );
- $key++;
- }
- endforeach;
- endforeach;
- if (count($filenames) > 1):
- $SEARCH_MATCH = array();
- $MOVIE_NAMES = array();
- $matches = array();
- foreach ($FILE_LIST as $index => $f)
- {
- if (isset( $matches[$f['name']] ) && !in_array($f['name'], $MOVIE_NAMES))
- {
- array_push($SEARCH_MATCH, $f);
- array_push($MOVIE_NAMES, $f['name']);
- }
- $matches[$f['name']] = $index;
- }
- elseif (!empty($FILE_LIST)):
- $SEARCH_MATCH = $FILE_LIST;
- endif;
- if (!empty($SEARCH_MATCH))
- {
- return $SEARCH_MATCH;
- }
- else
- {
- return "No files found\n";
- }
- }
- if (isset($_POST['search'])):
- $search = $_POST['search'];
- endif;
- if (isset($search)):
- $videos = glob_files($search, 'videos');
- endif;
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement