[英]Thank logged in user for file upload
我需要用戶以大寫字母感謝他們的名字。
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
在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.";
}
}
?>
我試過應用相同的模式,但由於某種原因它不起作用。
還要感謝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.";
}
}
?>
您只需要拆分文本和服務器輸入的部分即可。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.