cha0sriderx Posted October 9, 2007 Share Posted October 9, 2007 i was wondering how would you grab the file type of an image(like .png of blah.png or .jpg of hello.jpg.)? Quote Link to comment Share on other sites More sharing options...
d.shankar Posted October 9, 2007 Share Posted October 9, 2007 <?php $image="new.gif"; if (exif_imagetype($image) == IMAGETYPE_GIF) { echo 'The picture is a gif'; } elseif(exif_imagetype($image) == IMAGETYPE_JPEG) { echo 'The picture is a jpeg'; } elseif(exif_imagetype($image) == IMAGETYPE_PNG) { echo 'The picture is a png'; } else { echo "Image type unknown"; } ?> This is just an example. You can use case statements to be more appropriate. Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted October 9, 2007 Author Share Posted October 9, 2007 well i want to take a image file name and make the first part of it a set value and then just add the file extension at the end. Quote Link to comment Share on other sites More sharing options...
SammyGunnz Posted October 9, 2007 Share Posted October 9, 2007 Hmmm...reread. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 9, 2007 Share Posted October 9, 2007 If all you want is the extension of the file: <?php $file = "some.file.txt"; $tArr = explode(".", $file); $ext = $tArr[count($tArr) - 1]; $new_name = rand(5, 10) . $ext; echo $file . "<br>" . $new_name . "<br>"; ?> Bear in mind however, that the extension of the file has no bearing on the type of file. You need to use another mechanism to validate that a file is the type you are expecting, such as an image, plain text, etc. Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted October 9, 2007 Author Share Posted October 9, 2007 thanks for the help. i have an array that checks and makes sure the file is a valid image file. Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted October 9, 2007 Share Posted October 9, 2007 i have an array that checks and makes sure the file is a valid image file. What do you mean? Are you extracting the extension and just making sure it exists in Array( "gif", "jpg", "jpeg", etc. )? That's exactly what I said you shouldn't be doing. Quote Link to comment Share on other sites More sharing options...
cha0sriderx Posted November 5, 2007 Author Share Posted November 5, 2007 sorry never saw this reply. no actually i was getting the file extension so i could rename the file and keep the same extension. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 5, 2007 Share Posted November 5, 2007 if your uploading images you need echo $_FILES[nameoffield]["type"]; Quote Link to comment Share on other sites More sharing options...
roopurt18 Posted November 5, 2007 Share Posted November 5, 2007 No teng. The information there is not reliable. Quote Link to comment Share on other sites More sharing options...
teng84 Posted November 5, 2007 Share Posted November 5, 2007 No teng. The information there is not reliable. yah thats why added this one i guess with the answers we provided this is solved confusing question Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.