Your code fragment is most likely vulnerable to injection via $_POST ['Filename']. Someone could overwrite any file on the server that your account has write access to. Password protection of the script isn't enough, as you must plan against the possibility that someone will crack it.
On some OSs, you may have to deal with invalid filename characters; which characters are invalid depends on the filesystem. The X10 servers run Linux, which means they use extfs (in particular, the filesystem used on X10 currently is ext3). The only characters that are invalid in a file name under ext3 are "\0" (which PHP converts to an HTML character entity in form input) and "/" (which basename takes care of). Even though most any character is allowed in an extfs filename, it still is a good idea to be a little more restrictive in which characters you allow.
If the files being moved are not supposed to exist already, you can use file_exists to prevent overwriting of files.
Note that you can get the first part of the path from $_SERVER['DOCUMENT_ROOT'].
PHP Code:
function fsencode_piece($matched) {
$matched = $matched[0];
if ('-' == $matched) { # leading hypen
return '%2D';
} else if (' ' == $matched) {
return str_repeat('_', strlen($matched));
} else {
return urlencode($matched);
}
}
# Remove path, encode certain characters. Other encodings would also work. There
# might be additional characters that should be added to the regex.
$filename = preg_replace_callback('/^-| +|(?:[^[:print:]]|[^\x20-\x7E]|["&*:<>?\\|])+/', 'fsencode_piece', basename($_POST['Filename']));
$source = "$_SERVER[DOCUMENT_ROOT]/passwordplease/{$tempname}.{$fileext}";
$destination = "$_SERVER[DOCUMENT_ROOT]/{$filename}.{$fileext}";
if (! file_exists($destination)) {
rename($source, $destination);
}
Depending on your design requirements, you might want to make better use of [url=http://www.php.net/manual/en/features.file-upload.php]PHP's file uploading[/php] feature, including the move_uploaded_file function.