douye2020 2016-02-26 17:09
浏览 56
已采纳

如何阻止fwrite显示脚本末尾写入的字节数?

So I have a script that writes several pages and at the end is a html confirmation, at the top of the page is the amount of bytes written and doesn't it look right.

How do I stop this information from being displayed?

<?php
$filename = "".$page.".html";
$file = @fopen($filename,"x");
if($file)
{
echo fwrite($file,'html content');


fclose($file)

}   


?>
<!DOCTYPE html>
<html>

  <head>

   <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">

    <title>Thank You</title>

    <!-- Bootstrap Core CSS -->
    <link href="css/bootstrap.min.css" rel="stylesheet">

    <!-- MetisMenu CSS -->
    <link href="css/plugins/metisMenu/metisMenu.min.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="css/sb-admin-2.css" rel="stylesheet">

    <!-- Custom Fonts -->
    <link href="font-awesome-4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesnt work if you view the page via file:// -->
    <!--[if lt IE 9]>
        <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
        <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->



  </head>

      <body>

            <div class="row">
       <div class="col-lg-6">

                        <div class="panel-heading">

                        </div>
                        <!-- /.panel-heading -->
                        <div class="panel-body">
                            <div class="alert alert-success alert-dismissable">
                                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                                Thank you, site has been added successfully! <?php echo '<br><a href="http://www.example.com/';echo $filename; echo '">Click here to go to log page</a>'; ?>
                            </div>
<div style="margin-bottom: 10px;"> <a href="dashboard.html"><button class="btn btn-info" type="submit"><h3>Return to dashboard</h3></button></a></div>
                            </div>

                </div>
                <!-- /.col-lg-6 -->
            </div>
            <!-- /.row -->


       <!-- jQuery -->
    <script src="js/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="js/plugins/metisMenu/metisMenu.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="js/sb-admin-2.js"></script>

    <!-- Page-Level Demo Scripts - Notifications - Use for reference -->
    <script>
    // tooltip demo
    $('.tooltip-demo').tooltip({
        selector: "[data-toggle=tooltip]",
        container: "body"
    })

    // popover demo
    $("[data-toggle=popover]")
        .popover()
    </script>

      </body>

    </html>
  • 写回答

1条回答 默认 最新

  • duanduoding2238 2016-02-26 18:21
    关注

    Simple answer, this line echoes how many bytes were written on the call to fwrite:

    echo fwrite($file,'html content');
    

    The reason why, is fwrite returns this information, see the docs: http://php.net/manual/de/function.fwrite.php

    It's enough to call fwrite, without the echo:

    fwrite($file,'html content');
    

    If you want to extend on that, you can save the number of bytes in a variable, to trigger action in case of an error:

    $bytes = fwrite($file, $htmlContent);
    
    if (!$bytes && count($htmlContent)) {
      // Not written to file!
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况