Page 1 of 1

Upload script - replace and file extension.

Posted: Fri Dec 19, 2008 2:01 pm
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".

Re: Upload script - replace and file extention.

Posted: Fri Dec 19, 2008 2:21 pm
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.

Re: Upload script - replace and file extention.

Posted: Fri Dec 19, 2008 3:18 pm
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!";
}