Upload script - replace and file extension.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Upload script - replace and file extension.

Post by JKM »

Hi there!

I'm making an upload script, where I want to replace ":" with "-" - ex: "USER_ID:1345" with "USER_ID-1345". Also I was wondering how I can find the file extension - ex: ".rar".
Last edited by JKM on Fri Dec 19, 2008 3:19 pm, edited 1 time in total.
mukul_chou
Forum Newbie
Posts: 5
Joined: Tue Jun 17, 2008 4:23 am

Re: Upload script - replace and file extention.

Post by mukul_chou »

I want to replace
try

Code: Select all

str_replace ()
def. mixed str_replace ( mixed search, mixed replace, mixed subject [, int &count])
how I can find the file extention
explode() the file name string against . (period) and the last element of the arry is your extension. or
try

Code: Select all

substr()
def. string substr ( string string, int start [, int length]) to check last 4 cahrs == '.rar'

there is a file out there called php.chm Try to find this. this is the php ref manual. this file is extremely helpful.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Upload script - replace and file extention.

Post by JKM »

Like this?

Code: Select all

str_replace($userid, "USER_ID:", "USER_ID-")
and

Code: Select all

$file_extension = substr($filename , strrpos($filename , '. ') +1);
if($file_extension != "rar") {
    echo "The file isn't a rar file!";
}
Post Reply