olli460 Posted June 15, 2007 Share Posted June 15, 2007 Hello, i have a small website that has some downloads on it and i am in the process of uploading around 300 more files onto a different host. I was wondering if i can get some help i currently have all my files in a database and i have inserted the files one by one at the moment, i was wondering if it was possible to create a php file to grab all the files from an ftp/directory listing and insert them into a database on another server. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/ Share on other sites More sharing options...
pocobueno1388 Posted June 15, 2007 Share Posted June 15, 2007 If you get an FTP program you can transfer all the files at once (at least with mine). CoreFTP is a free FTP that allows you to do that. I'm not sure if there is an easier/faster way to do it someway else, but nothing comes to mind. Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/#findComment-275580 Share on other sites More sharing options...
olli460 Posted June 15, 2007 Author Share Posted June 15, 2007 Sorry, not sure i was clear enough. I want to keep the files on the ftp i just want to grab the contents and add it into the database so people can download the files off my website without me having to add every file seperatly Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/#findComment-275581 Share on other sites More sharing options...
AndyB Posted June 16, 2007 Share Posted June 16, 2007 Look at the manual for readdir() or glob() both of which will read the folder contents into an array. From there it should be pretty simple how to add a database row for each element of the array. Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/#findComment-275621 Share on other sites More sharing options...
olli460 Posted June 16, 2007 Author Share Posted June 16, 2007 Thanks, i will take a look. If anyone would like to do it for me i can pay them via paypal. Regards Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/#findComment-275683 Share on other sites More sharing options...
redarrow Posted June 16, 2007 Share Posted June 16, 2007 not tested but might work. put this in the same directory as the files then point to it via ur browser ok. if it works make a donation to phpfreaks in respect of me ok cheers <?php //database connection. $db=mysql_connect("localhost","username","password"); mysql_select_db("database_name",$db); // set the file type with the .exstetion name $filetype=".php"; // forech throm the folder to get the file names. foreach(glob("*$filetype") as $filename){ //insert the file names query $query="insert into colum_name(id,filename)values('$id','$filename')"; $result=mysql_query($query); // if the database updates tell me if(mysql_affected_rows($result)){ echo" database has been updated"; }else{ echo " database is not updated"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/55783-grabbing-directory-listing-and-inserting-to-a-db/#findComment-275747 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.