0 ? $destination . "/" : ""; // adds a file seperator if the destination isn't blank $fname = strtolower(ereg_replace("[ #%&?]", "_", $fname)); // change spaces to underscores and make lower case // to avoid file name collisions with older files, we're going to split the file name into its component // parts: the name and the extension. Then, we'll use the uniqid() function to create a random element // prefixed by the date in YYYYMMDD format in between those two sections so that this file will never be // named the same as another file. Because file names could include periods within them, we'll have to // split up the entire name into its component, period delimited sections and assume the extention is the // last one and the rest make up the name. $file_name_parts = explode(".", $fname); $extension = $file_name_parts[sizeof($file_name_parts)-1]; // extract the extension $name = join(array_slice($file_name_parts, 0, sizeof($file_name_parts)-1), ".");; // rejoin the rest as the name $filename = $name . "." . uniqid(date("Ymd").".", true) . "." . $extension; // and create the unique name // now we'll try to move the file. remember, we want to return false if ther are no errors, so if the // move function works, then we'll return false and if not, then we'll return an error code. $abs_filename = "$FILE_ROOT/media/uploads/" . $destination . $filename; if(move_uploaded_file($ftemp, $abs_filename)) return array(false, $filename); else return array(true, "cannot_move"); } function get_error_code($ferror) { $error = ""; switch($ferror) { case 1: case 2: $error = "too_large"; break; case 3: $error = "partial"; break; case 4: $error = "no_file"; break; case 6: $error = "no_temp_dir"; break; } return $error; } ?>