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
spacebiscuit
Forum Contributor
Posts: 390 Joined: Mon Mar 07, 2005 3:20 pm
Post
by spacebiscuit » Tue Nov 15, 2011 1:11 pm
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?
Celauran
Moderator
Posts: 6427 Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada
Post
by Celauran » Tue Nov 15, 2011 1:14 pm
$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
Post
by spacebiscuit » Tue Nov 15, 2011 1:24 pm
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!