thanks in advance everyone 🙂 🙂
I am trying to scan a server folder and output the contents to a comma separated text file for later import to mysql. (if I could load directory contents into mysql at the same time, even better!!)
I want the following values : file name, modify date, size
I have been able to echo out to the browser output that looks like this:
[FONT="Courier New"]counter_set.php,11/13/2007 03:33:17 PM,2 Kb
ftp_file_list_to_sql.php,11/13/2007 05:36:28 PM,2 Kb
ftp_list.php,11/13/2007 03:51:18 PM,1 Kb
readwrite.php,11/13/2007 03:37:55 PM,2 Kb[/FONT]
BUT - How do I get this result displayed in my browser written into a text file (or mysql table even better) ??😕
THANKS!!!!
[FONT="Courier New"]<?php
$host = 'hostname.net;
$user = 'username';
$pass = 'password';
$folder = '/hostname.net/public_html/php';
// connect to the ftp server and specific file
function get_content($host, $user, $pass, $folder) {
$content = array();
$conn = ftp_connect($host);
if ($conn) {
$session = ftp_login($conn, $user, $pass);
if ($conn) {
if (empty($folder) || ftp_chdir($conn, $folder)) {
$files = ftp_nlist($conn, ".");
if (is_array($files)) {
foreach($files as $file) {
$size = number_format(ftp_size($conn, $file)/1024).' Kb';
$date = date('m/d/Y h:i:s A', ftp_mdtm($conn, $file));
if ($size > 0) {
$content[] = array(
"name" => $file,
"url" => "ftp://$user:$pass@$host/$folder/$file",
"date" => $date,
"size" => $size
);
}
}
}
}
}
ftp_close($conn);
}
return $content;
}
$files = get_content($host, $user, $pass, $folder ); // reusing the array from above here
foreach ($files as $file) {
echo $file[name].','. $file[date].','.$file[size].'<br>';
}
?>[/FONT]