/    Sign up×
Community /Pin to ProfileBookmark

How To Use finfo_file() ?

Hi,

I try learning finfo file function but tutorials show complications.
Eg.

[code]
$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
foreach (glob(“*”) as $filename) {
echo finfo_file($finfo, $filename) . “n”;
}
finfo_close($finfo);
[/code]

What is **glob** ?
I do not get that line atall!

Can someone be kind of enough to show very basic and bare min sample code instead ?

I hear finfo file is tough nut to crack and you can get the correct file type user is trying to upload to your server.
Other functions to detect file type are easily breakable.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmJun 22.2022 — Guess what? It's In The Manual!

As for showing you sample code, what is wrong with the sample you posted???
Copy linkTweet thisAlerts:
@NogDogJun 22.2022 — https://www.php.net/glob

In your example, it's being used to loop through every file in the current directory. If you don't need to do that, then just leave out the loop syntax with the glob() command, and simply call finfo_file() with whatever file name you want to use.
Copy linkTweet thisAlerts:
@novice2022authorJun 23.2022 — @NogDog#1644810

You mean this ...
<i>
</i>$finfo = finfo_open(FILEINFO_MIME_TYPE); // return mime type ala mimetype extension
$filename = '../test.mp4'
finfo_close($finfo);


But it looks weird and empty. Will have to test it if that is what you meant.

Is that what you meant ?
Copy linkTweet thisAlerts:
@NogDogJun 23.2022 — You still have to do the finfo command that's inside the loop...you just don't need the loop.
×

Success!

Help @novice2022 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...