PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Sat May 19, 2007 10:55 pm
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.
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Sun May 20, 2007 12:16 am
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?
maliskoleather
Forum Contributor
Posts: 155 Joined: Tue May 15, 2007 2:19 am
Contact:
Post
by maliskoleather » Sun May 20, 2007 2:04 am
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.
stereofrog
Forum Contributor
Posts: 386 Joined: Mon Dec 04, 2006 6:10 am
Post
by stereofrog » Sun May 20, 2007 6:20 am
Code: Select all
foreach(glob("*.{jpg,png,gif}", GLOB_BRACE) as $fname)
if(getimagesize($fname))
// $fname is an image
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Wed May 23, 2007 9:29 pm
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?
Last edited by
JellyFish on Wed May 23, 2007 10:10 pm, edited 1 time in total.
maliskoleather
Forum Contributor
Posts: 155 Joined: Tue May 15, 2007 2:19 am
Contact:
Post
by maliskoleather » Wed May 23, 2007 11:04 pm
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.
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Thu May 24, 2007 12:18 am
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu May 24, 2007 12:20 am
Arbitrary modules can execute arbitrary code. The provider might not like that.
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Thu May 24, 2007 12:56 am
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?
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu May 24, 2007 12:59 am
Depends on how the extension is installed.
JellyFish
DevNet Resident
Posts: 1361 Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA
Post
by JellyFish » Thu May 24, 2007 1:18 am
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?
maliskoleather
Forum Contributor
Posts: 155 Joined: Tue May 15, 2007 2:19 am
Contact:
Post
by maliskoleather » Thu May 24, 2007 1:28 am
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu May 24, 2007 1:29 am
Just ask them. In the meanwhile getimagesize() will probably suffice.