10-17-2007, 08:51 PM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Sep 2007
Location: Leeds, UK
Posts: 141
Thanks: 6
|
Renaming Uploaded Files
Hey,
Have made a script that basically uploads a file... nothing special. I wanted to rename each file with the user's username, so if my username is Test User the file would rename to test_user.ext.
When I echo out the username and file name, they appear correct, but when I upload the image, it renames it to Array.ext. Not sure why it's outputting as an array, when I echo it out normally, it shows.
Here's some code:
PHP Code:
<?php
// Rename file according to username
foreach(getUser($_COOKIE['userID']) as $info) {
$ext = explode('.', $_FILES['upload_avatar']['name']);
$file_name = str_replace($ext[0], strtolower($info['username']), $ext);
// Avatar directory
$directory = 'images/avatar/'.$file_name.'.'.$ext[1];
// Move file to directory
move_uploaded_file($_FILES['upload_avatar']['tmp_name'], $directory);
}
?>
Can anyone see anything that I might have missed? Can't work my head around it :confused:
Thanks
__________________
Not quite a n00b...
|
|
|
|