簡體   English   中英

如何使用PHP檢查文件是否為bash文件?

[英]How to check if a file is a bash file with PHP?

我的網站上有一個功能,允許人們上傳各種類型的文件。 我不希望人們上傳bash文件,但我無法僅通過文件擴展名來判斷,因為據我所知,“。pdf”文件只能包含bash代碼。 有沒有一種方法可以檢查是否可以使用bash運行文件?

使用mime_content_type( http://php.net/manual/en/function.mime-content-type.php ):

// #!/bin/bash
$result = mime_content_type(/path/to/exmple);
$result = 'text/x-shellscrip';

// #!/bin/sh
$result = mime_content_type(/path/to/exmple);
$result = 'text/x-shellscrip';

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM