如何将二进制数据的大小发布到php?

My 3rd party app creates an image and store it in a variable and then post it to a php on the server. for security matters, I need to limit the upload size. Now that the binary data is not written to a file yet, how would I go around getting its size?

Here is the code:

<?php

$_data = $_POST['data']; //get the binary data from the client side.

    if($_data !=""){
       $handle = fopen($_path."/".$_ref.".png", "w");
       fwrite($handle,$_data);
    }

?>

Use

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

use $_FILES['filename']['size'] to get the uploaded filesize