Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.