jonniejoejonson Posted January 2, 2008 Share Posted January 2, 2008 I want to copy a file from another server which is failry simple... However I want to check that this file is a jpeg/giff and not a virus before I copy it to my server. Is there a way to check filetype? thanks to any responders J. Link to comment https://forums.phpfreaks.com/topic/84189-check-filetype/ Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 Use fileinfo. http://www.php.net/fileinfo Or the depreciated, mime_content_type. http://www.php.net/mime_content_type Link to comment https://forums.phpfreaks.com/topic/84189-check-filetype/#findComment-428626 Share on other sites More sharing options...
p2grace Posted January 2, 2008 Share Posted January 2, 2008 You could also explode it into a string $filename = "whatever.vr1.jpeg"; // I have multiple periods to show you that the code below will still work $filename_arr = explode(".",$filename); $filetype = $filename_arr[(count($filename_arr) - 1)]; if($filetype == "jpeg" || $filetype == "gif"){ // is a jpeg or a gif }else{ // error only jpeg or gif is allowed } Link to comment https://forums.phpfreaks.com/topic/84189-check-filetype/#findComment-428629 Share on other sites More sharing options...
hitman6003 Posted January 2, 2008 Share Posted January 2, 2008 You could also explode it into a string ... That doesn't check the file content, which makes it easier to rename a script to "whatever.jpg", and then execute it remotely. If the content type returns as something you don't want, you simply don't save the file. Link to comment https://forums.phpfreaks.com/topic/84189-check-filetype/#findComment-428640 Share on other sites More sharing options...
jonniejoejonson Posted January 2, 2008 Author Share Posted January 2, 2008 Thanks guys, Do you think that the following is enough protection when allowing people to copy ONLY jpeg or giff images from a server to your server? $contentType=mime_content_type($urlImage); if($contentType=='image/gif'||$contentType=='image/jpeg'){ copy($urlImage,"../images/".$saveImg)or die ('Could not copy'); } else {exit();} thanks J. Link to comment https://forums.phpfreaks.com/topic/84189-check-filetype/#findComment-428716 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.