Check file type (FLV) before PHP upload file in temporary folder by reading only starting 3 bytes of file

前端 未结 2 924
粉色の甜心
粉色の甜心 2020-12-31 05:21

First 3 bytes of FLV file are signature \"FLV\". Now my question:

Is there any possibility in PHP to handle file uploads so that we can hook into the input stream of

2条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 05:44

    First, set session.upload_progress.enabled in your php.ini.

    Then, use session.upload_progress to track how many bytes have uploaded. Once you have reached the minimum threshold, check the temporary file being uploaded, it will be in $_SESSION[unique_key]['files'][0]['tmp_name']. If the file doesn't match, set $_SESSION[unique_key]["cancel_upload"] to TRUE, and the file will be rejected.

    To get unique_key:

    ini_get("session.upload_progress.prefix") . $_POST[ini_get("session.upload_progress.name")];

    If the above does not work (I haven't tested it), then your only recourse would be to create your own custom handler for PHP either as an Apache module (or better, as a custom CGI application). There you could do your filtering.

提交回复
热议问题