php - 感谢登录用户上传文件
问题描述
我需要用大写感谢用户的名字。
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.";
}
}
?>
我尝试过应用相同的模式,但由于某种原因它不起作用。
解决方案
还要感谢 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.";
}
}
?>
您只需要拆分文本部分和服务器输入部分即可。
推荐阅读
- javascript - Diff2html 差异未加载
- python - 在python中,如何通过条件在一维数组的对应元素上快速设置二维数组每一行的值?
- java - 复制粘贴链接应该被重定向到主页
- siddhi - 检查 siddhiQL 中的非发生事件
- python - Jupyter 中的动画交互式绘图
- angular - 在 chrome 上为 Angular8 项目调试停止工作
- file - 测试 NTFS 文件条目
- android - Android Oauth2 对我的 Spring Server 进行身份验证
- java - 如何检查 Heroku 上正在运行的容器的日志?
- java - 无法从 search.maven.org 下载工件