http post - 如何获取发布到 php 的二进制数据的大小


http post - How to get the size of a binary data posted to a php?

我的第三方应用程序创建一个图像并将其存储在变量中,然后将其发布到服务器上的php。 出于安全考虑,我需要限制上传大小。现在二进制数据尚未写入文件,我将如何获取其大小?

这是代码:

<?php
$_data = $_POST['data']; //get the binary data from the client side.
    if($_data !=""){
       $handle = fopen($_path."/".$_ref.".png", "w");
       fwrite($handle,$_data);
    }
?>

使用

$length = strlen($_POST['data']);

使用 $_FILES['filename']['size'] 获取上传的文件大小