Page 1 of 2
Checking if a file is an image file.
Posted: Sat May 19, 2007 10:55 pm
by JellyFish
How do I check if an URI is a image file type?
I'm "scanning" through a directory and want to do somethings with only the files that are images.
How could I go about this?
Please help me with one.
Thanks for reading.
Posted: Sat May 19, 2007 11:03 pm
by volka
You might be interested in
http://de2.php.net/fileinfo
Posted: Sun May 20, 2007 12:16 am
by JellyFish
How do I use these? I don't have the set of functions apparently cause I get the error:
Fatal error: Call to undefined function: finfo_file() in /home/content/t/r/a/tradingtresure/html/manager/files.php on line 51
Does anyone have any other solutions?
Posted: Sun May 20, 2007 2:04 am
by maliskoleather
its basically the same as fopen/fread
Code: Select all
$finfo = finfo_open(FILEINFO_MIME);
echo finfo_file($finfo, $filename) . "\n";
finfo_close($finfo);
you need to install it though. the page linked above has the link and instructions to do so.
alternatively, you could use the
stat() or
mime_content_type() functions, though neither are as clean. fileinfo executes the process better.
Posted: Sun May 20, 2007 6:20 am
by stereofrog
Code: Select all
foreach(glob("*.{jpg,png,gif}", GLOB_BRACE) as $fname)
if(getimagesize($fname))
// $fname is an image
Posted: Wed May 23, 2007 9:29 pm
by JellyFish
maliskoleather wrote:its basically the same as fopen/fread
Code: Select all
$finfo = finfo_open(FILEINFO_MIME);
echo finfo_file($finfo, $filename) . "\n";
finfo_close($finfo);
you need to install it though. the page linked above has the link and instructions to do so.
alternatively, you could use the
stat() or
mime_content_type() functions, though neither are as clean. fileinfo executes the process better.
Am I allowed to install php extensions on a shared(I believe shared) hosting server, like godaddy?
Why would "they" depreciate mime_content_type() when they don't include the fileinfo extensions by default with PHP 5?
Posted: Wed May 23, 2007 9:53 pm
by volka
probably not, but maybe getimagesize() is available.
see
http://de2.php.net/getimagesize
Posted: Wed May 23, 2007 11:04 pm
by maliskoleather
JellyFish wrote:
Am I allowed to install php extensions on a shared(I believe shared) hosting server, like godaddy?
no. you could probably send them and email and ask for it. most hosts are glad to install extensions for users.
JellyFish wrote:
Why would "they" depreciate mime_content_type() when they don't include the fileinfo extensions by default with PHP 5?
because mime_content_type() is clunky, slow, and more work on the server than nessicary.
Posted: Thu May 24, 2007 12:18 am
by JellyFish
Would installing extensions take more space on their server or make pages run slower?
What does glob() do, i didn't quite understand on php.net? And what's glob stand for?
Posted: Thu May 24, 2007 12:20 am
by volka
Arbitrary modules can execute arbitrary code. The provider might not like that.
Posted: Thu May 24, 2007 12:56 am
by JellyFish
I see.
I'll contact them then.
But if they install the extension, will the extension be available for all other hosting customers or just for my account?
Posted: Thu May 24, 2007 12:59 am
by volka
Depends on how the extension is installed.
Posted: Thu May 24, 2007 1:18 am
by JellyFish
They'll most likely install to my local directory access right?
Or would they actually install it for everyone? Have they(hosting services) ever done that?
Posted: Thu May 24, 2007 1:28 am
by maliskoleather
depends on how they have php set up and configured.
Some hosts will install it for one user, some hosts will install it for everyone on that server.
It just depends.
Posted: Thu May 24, 2007 1:29 am
by volka
Just ask them. In the meanwhile getimagesize() will probably suffice.