Ok, I downloaded a script that reads all the zip files in the directory it's in and displays them on a page, with the file size aswell.
I then changed it a bit, so it would add the files to a database instead of displaying them on a page. But I need help with two things. (I then call them with a more complex download script)
First off here is the script:
<?php
require("config.php");
require("functions.php");
$ffdb=new Ffdb;
$ffdb->StartTimer();
$tpl=new Templates;
$mysql=new Mysql;
$mysql->Connect();
set_magic_quotes_runtime(0);
error_reporting (E_ERROR | E_WARNING | E_PARSE);
// Ok Time to do some HTML fun!
?>
<?php
$handle=opendir('.');
while (($file = readdir($handle))!==false){
rtrim($file);
if($file=="."){
$file=readdir($handle);
$file=readdir($handle);
}
if($file=="hits.txt"){
$file=readdir($handle);
}
if(eregi("[a-zA-Z0-p_-]*.zip",$file)!==false){
$spliter=explode(".",$file);
$filea="$spliter[0].zip";
$filei="TEXT INFO";
$filez="$spliter[0].zip";
$size=filesize($filez);
$size=($size/1000);
$size=round($size,1);
$info=" Text info files have not yet been created..";
echo "Adding $spliter[0] <br>";
$mysql->Query("INSERT INTO `downloads` ( `size` , `name` , `url` ) VALUES ('$size', '$spliter[0]', '$filea')");
echo "$spliter[0]. Added Successfully</br>";
$filer="$file";
$file=file($filer);
$sline=0;
$count=count($file);
$eline=$count;
$i = $count;
for($j=$sline;$j<$eline;$j++){
}
} else {
}
}
?>
Where it says
$mysql->Query("INSERT INTO `downloads` ( `size` , `name` , `url` ) VALUES ('$size', '$spliter[0]', '$filea')");
there was originally an echo command that would just show the files on that index.php
This works, and if I were to upload 5000 files in the directory, and go to this (which I called "add.php") all 5000 files would automatically be added, however there are two more things that I need to do.
I want to make this even more efficient, by setting this to run every hour or so using a cron job...the problem is, right now it would keep on adding all of the same files over and over again.
So request 1 is: Can you help me make it so it queries the table "downloads" to find out which files have already been added there, and for it to ignore the already added files and add the new files.
Secondly, my site orders all files alphabetically, but in order to do this easily in each file row there is a field called "letter", which goes from 1 - 27 (1 = A, 26 = Z, 27 = 0-9) Is there a way to use php to find out the first letter of the files in the directory, and then add the appropiate number (ie: if the file begins with an "b", then it would be able to add the number "2")
Thanks in advance.