[英]Thank logged in user for file upload
I need the user to be thanked in uppercase for their name. 我需要用户以大写字母感谢他们的名字。
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.";
The code above works. 上面的代码有效。 I've tried this:
我试过这个:
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.";
but that just outputs it. 但那只是输出它。 Any help making the user's name uppercase in this format would be appreciated.
任何帮助使用这种格式的用户名称大写将不胜感激。
EDIT
After the comment from Tim I tried applying this to the rest of the possible messages but this is not working for some reason and I'm not sure why. 在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.";
}
}
?>
I've tried applying the same pattern but for some reason it isn't working. 我试过应用相同的模式,但由于某种原因它不起作用。
Also with thanks to Tim, this works for the whole code; 还要感谢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.";
}
}
?>
You just need to split the sections for the text and the server input for it to work. 您只需要拆分文本和服务器输入的部分即可。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.