Forum Moderators: coopster
can anyone help out?
here's the code:
<?
$the_array = Array();
$handle = opendir('/home/www/juttuffi/midi/files');
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= "..") {
$the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
while (list ($key, $val) = each ($the_array)) {
echo "<a href=http://example.co.uk/midi/files/$val target=_blank>$val</a><br>";
}
?>
[edited by: jatar_k at 7:29 pm (utc) on June 30, 2004]
[edit reason] generalized url [/edit]
if ($file!= "." && $file!= "..") {
$the_array[] = $file;
}
so we don't want directories in the array?
!is_dir($file)
and we want to test the file extension to see if it is .mid
$namearr = split('.',$file);
if ($namearr[count($namearr)-1]!= 'mid')
makes sense, so how do we add it
if ($file!= "." && $file!= ".." &&!is_dir($file)) {
$namearr = split('.',$file);
if ($namearr[count($namearr)-1]!= 'mid') $the_array[] = $file;
}
might even work, I sure didn't test it ;)
<?
$the_array = Array();
$handle = opendir('/home/www/juttuffi/midi/files');
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= ".." &&!is_dir($file)) {
$namearr = split('.',$file);
if ($namearr[count($namearr)-1]!= '.mid') $the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
while (list ($key, $val) = each ($the_array)) {
echo "<a href=http://example.co.uk/midi/files/$val target=_blank>$val</a><br>";
}
?>
i used it as ",mid" and "mid" no effect mate, im not gettin any errors mind so maybe its just the cache, ill check it in an hour but nah no effect. Cheers for the help man
dont spose anyone else or or u maybe know whats up jatar?
[edited by: jatar_k at 10:55 pm (utc) on June 30, 2004]
[edit reason] no personal urls thanks [/edit]
<?
$the_array = Array();
$handle = opendir('/home/www/juttuffi/midi/files');
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= ".." &&!is_dir($file)) {
$namearr = split('\.',$file);
if ($namearr[count($namearr)-1] == 'mid') $the_array[] = $file;
echo "<p>$file<br><pre>";
print_r($namearr);
echo "</pre>";
}
}
closedir($handle);
sort ($the_array);
reset ($the_array);
while (list ($key, $val) = each ($the_array)) {
echo "<a href=http://example.co.uk/midi/files/$val target=_blank>$val</a><br>";
}
?>
forgot to escape the . in the split and had!= 'mid', it would make a lot more sense as == 'mid' ;)