Hey all.This is intended for uploading multiple files and displaying their content on screen which is supposed to be limited by the $num_of_uploads in the for loop. For example if I apload 2 files it should display only 2 files and next time when i upload another number of files it should display the newely uploaded files just added to the old ones. I have a function which reads a directory and sorts the files according to time they are entered with filemtime. I have functions callAttachmentExists and createCallAttachment to check if attachement already exsist and create call attachment for sending the attached files to the database.They are working fine. The problem seems to be in the for loop because while displaying what is in the database i only want to see on the display the two latest files added to the already exsisting files.but now for some reason it is displaying more times which means it is sending old files again to the database and displays them. Forexample first i upload ann.php and mary.php. It displays ann.php.mary.php
next i upload mark.php and tedy.php it displays ann.php,mary.php,mark.php,tedy.php,ann.php,mary.php the intention was so that it displays 4 files instead of displaying ann and mary again. Oh I know I might not be very clear but hope you guys understand and help me as soon as possible.
function compare($a,$b){
return $b[1]-$a[1];
}
function read_dir($path) {
$files = Array();
if ($handle = opendir($path)) {
while (false !== ($fileSName = readdir($handle))) {
if ($fileSName != "." && $fileSName != "..") {
$files[] = Array($fileSName,filemtime($path.$fileSName));
}
}
closedir($handle);
}
return $files;
}
$files = read_dir($path);
usort($files,"compare");
for($i=0;$i<$num_of_uploads;$i++){
$filename = $files[$i][0];
echo "$filename";
if( !callAttachmentExists( &$connection, $call_id,$filename )) {
createCallAttachment( &$connection, $call_id, $filename );
}}