sgt_fireman Posted August 9, 2012 Share Posted August 9, 2012 Hey guys, so I was trying to create something that very simply gets the file extension for me, however for some reason the output of $xnt is the first letter of the uploaded file, and not the extension, Any Ideas anyone? Thank-you very much in advance. $path2 = $_FILES['uploadedfile']['name']; $xnt = ($path2['extension']); echo $xnt; die(); Quote Link to comment https://forums.phpfreaks.com/topic/266877-pathinfo/ Share on other sites More sharing options...
BuildMyWeb Posted August 9, 2012 Share Posted August 9, 2012 ive used: $file_name_raw = $_FILES['uploaded_file']['name']; // extension of the uploaded file $file_ext = substr( strrchr($file_name_raw, '.') ,1 ); Quote Link to comment https://forums.phpfreaks.com/topic/266877-pathinfo/#findComment-1368197 Share on other sites More sharing options...
Christian F. Posted August 9, 2012 Share Posted August 9, 2012 sgt_fireman: I think you've forgot something in that code block... BuildMyWeb: I'd look into the function that the OP mention, if I were you. Much cleaner way to deal with stuff like that. Quote Link to comment https://forums.phpfreaks.com/topic/266877-pathinfo/#findComment-1368199 Share on other sites More sharing options...
sgt_fireman Posted August 9, 2012 Author Share Posted August 9, 2012 Thank-you BuildMyWeb, That worked fine! Quote Link to comment https://forums.phpfreaks.com/topic/266877-pathinfo/#findComment-1368202 Share on other sites More sharing options...
jazzman1 Posted August 9, 2012 Share Posted August 9, 2012 @sgt_fireman, you have to consider your decisions working with files and uploading them to the server and database. @BuildMyWeb, strrchr is a pretty tricky function (I've never used it), but.... what about this ? It's a real file extension ? $str = 'file_test. php'; $file_ext = substr( strrchr($str, '.') ,true); var_dump($file_ext); Quote Link to comment https://forums.phpfreaks.com/topic/266877-pathinfo/#findComment-1368217 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.