function to change filename not working

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
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

function to change filename not working

Post by dhrosti »

Iv been trying to get my head round whats going wrong for ages and cant figure out why this doesnt work...

Code: Select all

function filename() {
	// format: client_type_date.ext
	$client = $_POST['client'];
	$client = strtolower(str_replace(' ', '', $client));
	$type = $_POST['type'];
	$type = strtolower(str_replace(' ', '', $type));
	$date = date('d_m_Y');
	$mimetype = $_FILES['userfile']['type'];
	$ext = substr(strrchr($mimetype, "."), 1);
	return "$client_$type_$date.$ext";
}
It just returns "16_01_2007." as the filename. No underscores before $date, as id expect if the variables werent set.

Any help is much appreciated.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

then it should be

Code: Select all

return $client._.$type._.$date.$ext;
:o
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Post by dhrosti »

Right, i'v got the file extension fixed (my script was looking for a "." in a mimetype thing such as, image/jpeg)

Still not creating the $client or $type variables.
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Post by dhrosti »

that sorted it, thanks.

just needed to put the dot before $ext in quotes
Post Reply