[英]PHP Script ,php://input check for empty File
您好,我的 PHP 腳本需要幫助。 上傳 function 效果很好,但很多文件都是空的。
你能幫我檢查一下如果文件是空的或 < 1 字節。 並忽略它們。
<?php
$vist_page = "post2.php";
include "logger.php";
file_put_contents("outputfile.txt".uniqid(), file_get_contents("php://input"));
?>
謝謝;)
一種方法是使用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
}
$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
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.