Hello friends, I have a file upload system where users can upload file and I store the files on the separate folder but I upload the files' names in the mysql DB. Now what I want to do is to remove all the letter after the dot sign i.e the extension and only upload the name of the file without the extension name. For example if the file's name is syllabus.zip I want to remove 'zip' and be left alone with only 'syllabus'. Could you please tell me how to do that? Thank you! Best Regards Stefany
Found something via google that might help you out! From stackoverflow http://stackoverflow.com/questions/2395882/how-remove-extension-from-string-only-real-extension Code (markup): Hope that helps!
I would probably do something like this. $original = 'syllabus.zip'; $file_name = substr($original,0,strpos($original,'.')); PHP: This will remove everything after and including the period. I don't think there is a more efficient way of doing this.
Of all the ones above, use pathinfo... specifically $filename=pathinfo($originalName,PATHINFO_FILENAME); http://php.net/manual/en/function.pathinfo.php When dealing with files, pathinfo, and it's cousin parse_url http://php.net/manual/en/function.parse-url.php Are indispensable. It's also why it's a laugh when people start using brute force with regex or strpos to do it.
do not use strpos how about grey.abc.txt strpos will return first occurence of dot and the part of the file name you get will be 'grey' ( but it should be grey.abc as txt is only extension) use strrpos instead . strrpos returns last occurence of the period.