File Upload

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
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

File Upload

Post by spacebiscuit »

Hi,

i'm using the following function to upload images:

Code: Select all

move_uploaded_file($_FILES['cover']['tmp_name'],$path);
It works but I want to give the file a name of my choosing, at present it uses the original file name.

Is this possible?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: File Upload

Post by Celauran »

$path is user-defined so, strictly speaking, you're already doing that.

Code: Select all

$filename = "whatever";
$moved = move_uploaded_file($_FILES['cover']['tmp_name'], $path . DIRECTORY_SEPARATOR . $filename);
spacebiscuit
Forum Contributor
Posts: 390
Joined: Mon Mar 07, 2005 3:20 pm

Re: File Upload

Post by spacebiscuit »

Perfect that worked!

I did not realise that I had already been setting the filename in my code here:

Code: Select all

$path=$dir . basename( $_FILES['cover']['name']);
I just removed the basename() function and added my own filename.

Thanks!
Post Reply