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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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); ?> Quote Link to comment Share on other sites More sharing options...
shahzad Posted March 17, 2010 Author Share Posted March 17, 2010 thanku you Devotee it worked Quote Link to comment 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.