Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
265 views
in Technique[技术] by (71.8m points)

php - Get image extension

I want get uploaded image extension.

As I know, best way is getimagesize() function.

but this function's mime, returns image/jpeg when image has .jpg or also .JPEG extension.

How can get exactly extension?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

you can use image_type_to_extension function with image type returned by getimagesize:

$info = getimagesize($path);
$extension = image_type_to_extension($info[2]);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...