Re: Directory list - showing an image for each file
| From: | Richard Lynch | Date: | Mon, 08 Jan 2001 06:15:30 +0000 |
| Subject: | Re: Directory list - showing an image for each file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-33192@lists.php.net to get a copy of this message | ||
A couple ideas occur to me.
1) There's a facility in Apache to do this, I think... Read httpd.conf
2) You could at least have multiple cases and they "fall through" to the
same value:
switch(...){
case '.mp3':
case '.au':
case '.wav':
case '.snd':
case '.aiff':
case '.rm':
case '.ra':
$fileTypeImage = "sound.gif";
break;
case '.gif':
case '.jpg':
$fileTypeImage = 'image.gif';
break;
}
3) Perhaps an array would make more sense....
$fileTypeImages = array('.mp3' => 'sound.gif',
'.snd' => 'sound.gif',
.
.
);
$fileTypeImage = $fileTypeImage[$ext];
Another possiblity is to have it all in a database table, if you're already
using a databse connection anyway.
That way, you needn't edit your source code every time a new file format
pops up -- Just build a quickie web interface to your database table.
You do realize, of course, that technically, you can't guarantee that your
extension mapping will be correct -- If somebody really wanted to play with
your mind, they *could* use .gif for PHP and .php for GIF... :-)
----- Original Message -----
From: "Joe Nelson" <nelsonj@inconnect.com>
Newsgroups: php.general
Sent: Sunday, January 07, 2001 1:42 PM
Subject: [PHP] Directory list - showing an image for each file
> I'd like to show an image for each type of file in a directory list. I
wrote
> this function, but as you can see, it can get out of hand pretty easily.
> Does anyone know of a better way? Here's the function:
>
> function getFileType($file) {
> // Find the position of the last "." in the file name
> $pos = strrpos( $file, "." );
>
> // Extract the file extension using $pos
> $ext = strtolower( substr( $file, $pos ) );
>
> // Determine what type of icon to use for this file type
> file://-- **** Is there a better way to do this? **** --//
> switch ( $ext ) {
> case ".mp3":
> $fileTypeImage = "sound.gif";
> break;
> case ".wav":
> $fileTypeImage = "sound.gif";
> break;
> case ".au":
> $fileTypeImage = "sound.gif";
> break;
> case ".jpg":
> $fileTypeImage = "image.gif";
> break;
> case ".gif":
> $fileTypeImage = "image.gif";
> break;
> case ".avi":
> $fileTypeImage = "movie.gif";
> break;
> case ".mpg":
> $fileTypeImage = "movie.gif";
> break;
> case ".mpeg":
> $fileTypeImage = "movie.gif";
> break;
> case ".mpe":
> $fileTypeImage = "movie.gif";
> break;
> case ".mpa":
> $fileTypeImage = "movie.gif";
> break;
> case ".mov":
> $fileTypeImage = "movie.gif";
> break;
> case ".qt":
> $fileTypeImage = "movie.gif";
> break;
> case ".ram":
> $fileTypeImage = "movie.gif";
> break;
> default:
> $fileTypeImage = "unknown.gif";
> }
> return $fileTypeImage;
> }
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>