【问题标题】:PHP Script ,php://input check for empty FilePHP脚本,php://输入检查空文件
【发布时间】:2021-11-21 15:16:28
【问题描述】:

您好,我的 PHP 脚本需要帮助。 上传功能很好用,但是很多文件都是空的。

您能帮我检查一下第一个 IF 文件是否为空或

   <?php
    $vist_page     =   "post2.php";
    include "logger.php";
    file_put_contents("outputfile.txt".uniqid(), file_get_contents("php://input"));
    ?>

谢谢 ;)

【问题讨论】:

    标签: php upload


    【解决方案1】:

    一种方法是使用strlen() 来检查字符串的长度,这可以通过替换来完成

    file_put_contents("outputfile.txt".uniqid(), file_get_contents("php://input"));
    

    $content = file_get_contents("php://input");
    if (strlen($content)) {
        file_put_contents("outputfile.txt".uniqid(), $content);
    }
    else {
        // Your error response here
    }
    

    【讨论】:

    • 谢谢它很好用 ;)
    【解决方案2】:
    $filename = 'somefile.txt';
    if (filesize($filename) < 1) {
    //ignore
    
    } else {
    //do stuff here
    
    }
    

    filesize 返回文件大小(以字节为单位) https://www.php.net/manual/en/function.filesize.php

    这可能更有效:

    $filename = 'somefile.txt';
    if (filesize($filename) > 0) {
    //do stuff here
    
    } 
    

    【讨论】:

      猜你喜欢
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 2013-06-14
      • 2010-12-31
      相关资源
      最近更新 更多