chnaging the name of uploaded file

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
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

chnaging the name of uploaded file

Post 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?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: chnaging the name of uploaded file

Post 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.
Post Reply