shahzad Posted March 16, 2010 Share Posted March 16, 2010 i have around 200 images in a folder i want to upload it to the server and i want to store there name in mysql database. i know the script to upload 1 at a time but i need to select the file every time is it possible to give directory path and script will get all the images and get there name insert to the database?? thanks for your time and help in advance Link to comment https://forums.phpfreaks.com/topic/195424-upload-image-and-insert-image-name-in-database/ Share on other sites More sharing options...
litebearer Posted March 16, 2010 Share Posted March 16, 2010 Rather than upload one at a time via a script, it might be faster to ftp them. Then you could run a simple script to run thru the folder grabbing each name and inserting it into your database table Link to comment https://forums.phpfreaks.com/topic/195424-upload-image-and-insert-image-name-in-database/#findComment-1026914 Share on other sites More sharing options...
shahzad Posted March 16, 2010 Author Share Posted March 16, 2010 excellent idea litebearer... how to grab name of file in folder... can you please help me with function name or what it called so that i can learn to use it.. thanks again Link to comment https://forums.phpfreaks.com/topic/195424-upload-image-and-insert-image-name-in-database/#findComment-1026916 Share on other sites More sharing options...
Wolphie Posted March 16, 2010 Share Posted March 16, 2010 If the files are local, then you shouldn't need to do any file transfers, but rather just provide the path name to the directory. This is just an example, appropriate error handling is required. <?php // Open directory $dir = opendir('path/to/directory'); // List files in images directory while (($filename = readdir($dir)) !== false) { if ($filename != '.' || $filename != '..') { // You will need appropriate error handling $sql = mysql_query("INSERT INTO table_name ( filename ) VALUES ( '". $filename ."' )"); } } closedir($dir); ?> Link to comment https://forums.phpfreaks.com/topic/195424-upload-image-and-insert-image-name-in-database/#findComment-1026918 Share on other sites More sharing options...
shahzad Posted March 17, 2010 Author Share Posted March 17, 2010 thanku you Devotee it worked Link to comment https://forums.phpfreaks.com/topic/195424-upload-image-and-insert-image-name-in-database/#findComment-1027476 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.