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.)? Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/ 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365177 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365635 Share on other sites More sharing options...
SammyGunnz Posted October 9, 2007 Share Posted October 9, 2007 Hmmm...reread. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365639 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365640 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365774 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-365781 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-384716 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"]; Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-384726 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. Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-384730 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 Link to comment https://forums.phpfreaks.com/topic/72410-solved-getting-part-of-a-string/#findComment-384733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.