Page 1 of 1

chnaging the name of uploaded file

Posted: Thu Mar 03, 2011 2:08 pm
by someguyhere

Code: Select all

		$target_path = $target_path . basename( $_FILES['headshot']['name']); 
		
		if(move_uploaded_file($_FILES['headshot']['tmp_name'], $target_path)) {
		    $headshot = str_replace('/home/efarrell/public_html', '', $target_path);
		}
I have the following variables that I'd like to use: $f_name and $l_name. I would like the file to be named FirstName-LastName.jpg but I have no idea how to go about this. Can someone point me in the right direction?

Re: chnaging the name of uploaded file

Posted: Thu Mar 03, 2011 2:17 pm
by John Cartwright
Change

Code: Select all

$target_path = $target_path . basename( $_FILES['headshot']['name']); 
to

Code: Select all

$extension = array_pop(explode('.',  basename( $_FILES['headshot']['name']))); //get the file extension
$target_path = $target_path . $f_name .'-'. $f_name .'.'. $extension; //specify the target file location
The target path you can specify as anything you want, basically.