我需要感谢用户的大写名字。
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "Thank You, {$_SERVER['PHP_AUTH_USER']}. The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
上面的代码有效。我已经尝试过:
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "Thank You, ucfirst({$_SERVER['PHP_AUTH_USER']}). The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
但这只是输出。对于将用户名以此格式大写的任何帮助,将不胜感激。
EDIT
在蒂姆发表评论后,我尝试将其应用到其余可能的消息中,但是由于某些原因,该消息不起作用,我不确定为什么。
if (file_exists($target_file)) {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", the file already exists. Please try renaming or adding a version number.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "Thank You, ".ucfirst($_SERVER['PHP_AUTH_USER']).". The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", there was an error uploading your file.";
}
}
?>
我尝试应用相同的模式,但是由于某种原因,它不起作用。
答案 0 :(得分:0)
还要感谢Tim,它适用于整个代码;
if (file_exists($target_file)) {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", the file already exists. Please try renaming or adding a version number.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "Thank You, ".ucfirst($_SERVER['PHP_AUTH_USER']).". The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo " Sorry ".ucfirst($_SERVER['PHP_AUTH_USER']).", there was an error uploading your file.";
}
}
?>
您只需要分割文本和服务器输入内容的部分,即可使用。