[英]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.