Okay, so I'm bored and decided to add some files to my website for my amusement. I went looking through my archived PHP tutorials and found one for listing file info from a directory, so I'm putting it to work in my downloads directory, which is just where I upload random crap to give to someone else. Everything was going well, until I started trying to add more to it. Here's the code:
PHP Code:
<?php
$path = "downloads/";
$dir_handle = @opendir($path) or die("Unable to open $path");
while ($file = readdir($dir_handle)) {
if(!is_dir($file)) {
$filesize = round(filesize($path.$file)/131072, 2);
$mimetype = mime_content_type($path.$file);
echo "Name: $file<br>File Size: [ $filesize MB ]<br>Mime: $mimetype<br><a href=$path$file>Download file</a><br>------<br>";
}
}
closedir($dir_handle);
?>
and the output:
Quote:
application/x-zip Name: invboard1_2f.zip
File Size: [ 9.66 MB ]
Mime: application/x-zip
Download file
------
|
Now the part that's bugging me is the mime type displaying before Name:. Nothing
should appear before that the way I understand it, because it's the only output/display type line. Everything else is function or alias asignment. While I can see why it would show before Name, I can't figure out why it's showing up at all. It's the in the same format as the alias above it. The only other thing in the file is the mime_content_type function because the actual PHP function of the same name doesn't work correctly on my server. I actually pulled this off the PHP.net comments about the function itself as a "if your function errors out, use this to simulate it instead" kind of thing.
PHP Code:
if ( ! function_exists ( 'mime_content_type ' ) )
{
function mime_content_type ( $f )
{
return system ( trim( 'file -bi ' . escapeshellarg ( $f ) ) );
}
}
Looking at the preview before I post this, it apprears that the PHP bbcode tag parser agrees with Notepad++. There isn't anything missing from the code to mess it up. Any ideas?