dsfg3241 2019-06-19 23:11
浏览 84
已采纳

感谢登录用户进行文件上传

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.

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.

  • 写回答

1条回答 默认 最新

  • dongxiansi0158 2019-06-20 00:19
    关注

    Also with thanks to Tim, this works for the whole code;

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器