Jump to content

Grabbing directory listing and inserting to a DB


olli460

Recommended Posts

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!

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.

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";
}
}
?> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.