PhilipK Posted May 16, 2011 Share Posted May 16, 2011 Here is my problem I have a folder with 2500 image files. I need to get all of the file names into a MySQL database. Writing them in manually is not an option! Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/236568-trouble-getting-file-name-values/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2011 Share Posted May 16, 2011 glob Quote Link to comment https://forums.phpfreaks.com/topic/236568-trouble-getting-file-name-values/#findComment-1216140 Share on other sites More sharing options...
PhilipK Posted May 16, 2011 Author Share Posted May 16, 2011 Short and sweet... Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/236568-trouble-getting-file-name-values/#findComment-1216147 Share on other sites More sharing options...
PhilipK Posted May 16, 2011 Author Share Posted May 16, 2011 Hey sorry but I'm still having a bit of trouble. Here is what I have so far... $images = glob("images/{*.jpg,*.gif,*.png}", GLOB_BRACE); print_r($images); How can I edit the code I have here to use INSERT INTO instead of print_r. Thanks and sorry for the noob questions! Quote Link to comment https://forums.phpfreaks.com/topic/236568-trouble-getting-file-name-values/#findComment-1216156 Share on other sites More sharing options...
PFMaBiSmAd Posted May 16, 2011 Share Posted May 16, 2011 Assuming you want one row in your table for each filename, I would use array_chunk to break the list of files down into reasonable size chunks of around 500 files each. Then I would loop over those chunks and implode each group into a multi-insert query. $chunks = array_chunk($images, 500); // break into reasonable size pieces foreach($chunks as $chunk){ $imp = implode("'),('",$chunk); // implode the data to make a mulit-insert query $query = "INSERT INTO your_table (file_name) VALUES ('$imp')"; //echo $query . '<br />'; mysql_query($query) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/236568-trouble-getting-file-name-values/#findComment-1216197 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.