shanejeffery86 Posted October 25, 2008 Share Posted October 25, 2008 Hey guys. I have some files on my web server and I need to search through their files name with a certain string. That string will change based upon the record that the loop is on (using a foreach loop to run through my array). Right now, the files are named like such -- ESC-440_Paper_Bassalee. Therotically, if I could get all of the file names in that specific folder to be converted to string names, that would be ideally. Then I could just explode the strings with the "_" delimiter and then search the arrays for the relationship. Anyone have ANY idea how to handle this? Thanks. Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/ Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 Can I see the current array and code? I have an idea. Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/#findComment-674677 Share on other sites More sharing options...
shanejeffery86 Posted October 25, 2008 Author Share Posted October 25, 2008 <?php ini_set("memory_limit", "160M"); error_reporting(E_ALL); include("database_connection.php"); include("../scheduler_sv/lib/DB.class.php"); require_once '../SpreadsheetReader/SpreadsheetReaderFactory.php'; $spreadsheetsFilePath = '/var/www/html/cmp/downloads/boston_speaker.csv'; $reader = SpreadsheetReaderFactory::reader($spreadsheetsFilePath); $sheets = current($reader->read($spreadsheetsFilePath)); foreach($sheets as $record) { // echo '<pre>'; // print_r($record); // echo '</pre>'; $session_code = $record[0]; $speaker_name = $record[1]." ".$record[2]; $session_name = $record[3]; $session_date_result = explode(",", $record[4]); $session_date = $session_date_result[0]; $session_conference = 226; $query = "INSERT INTO phpfox_downloads (conference, session_code, session_name, date, author_name) VALUES ('".es($session_conference)."', '".es($session_code)."', '".es($session_name)."', '".es($session_date)."', '".es($speaker_name)."')"; mysql_query($query) or die(mysql_error()); } function es($var) { return mysql_real_escape_string($var); } ?> Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/#findComment-674696 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 Well, you might want to check out the glob() function. It allows you to get an array of all filenames matching a specific pattern. Also, please use tags when posting code. Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/#findComment-674700 Share on other sites More sharing options...
shanejeffery86 Posted October 25, 2008 Author Share Posted October 25, 2008 GOT IT! Code: $source_folder = '/var/www/html/cmp/downloads/esc_boston/'; $sec = 1; $limit = 200; $file_list = glob_files($source_folder, $sec, $limit); Function Call: function glob_files($source_folder, $sec, $limit){ if( !is_dir( $source_folder ) ) { die ( "Invalid directory.\n\n" ); } $FILES = glob($source_folder."/*"); $set_limit = 0; foreach($FILES as $key => $file) { if( $set_limit == $limit ) break; if( filemtime( $file ) > $sec ){ $FILE_LIST[$key]['name'] = substr( $file, ( strrpos( $file, "/" ) +1 ) ); $set_limit++; } } if(!empty($FILE_LIST)){ return $FILE_LIST; } else { die( "No files found!\n\n" ); } } Thank you VERY much! Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/#findComment-674730 Share on other sites More sharing options...
DarkWater Posted October 25, 2008 Share Posted October 25, 2008 No problem. Please mark this topic as solved. Link to comment https://forums.phpfreaks.com/topic/130114-solved-searching-file-name-for-string-with-php/#findComment-674733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.