本文目錄一覽:
- 1、PHP 沒有後綴名的文件怎麼獲取後綴
- 2、apache php 配置無後綴文件也可以解析
- 3、如何讓非.php後綴名的文件,以php腳本的形式
- 4、如何讓非.php後綴名的文件,以php腳本的形式運行
PHP 沒有後綴名的文件怎麼獲取後綴
我給你思路吧
首先沒有後綴,那隻能通過文件頭來判斷了
function getFileType($file){
if(!empty($file)){
//打開文件
$filehead = fopen($file,’r’);
//讀取文件2字節
$bin = fread($filehead, 2);
fclose($filehead);
//二進制字符串對數據進行解包
$data = unpack(‘C2chars’, $bin);
$type_code = intval($data[‘chars1’].$data[‘chars2’]);
switch ($type_code) {
case 7790:
$fileType = ‘exe’;
break;
case 7784:
$fileType = ‘midi’;
break;
case 8075:
$fileType = ‘zip’;
break;
case 8297:
$fileType = ‘rar’;
break;
case 255216:
$fileType = ‘jpg’;
break;
case 7173:
$fileType = ‘gif’;
break;
case 6677:
$fileType = ‘bmp’;
break;
case 13780:
$fileType = ‘png’;
break;
default:
$fileType = ‘unknown’;
break;
}
return $fileType;
}
–
apache php 配置無後綴文件也可以解析
1、設置test.php為默認文檔
2、設置偽靜態(確切的說是url重寫)
如何讓非.php後綴名的文件,以php腳本的形式
在WINDOWS上嗎,需要建立文件關聯,可以資源管理器文件類型修改,可以雙擊文件選擇,可以修改註冊表,還可以使用下面的DOS命令:
assoc .php=PHPFile
ftype PHPFile=d:\php\php.exe “%0” %*
如何讓非.php後綴名的文件,以php腳本的形式運行
進入php源程序目錄中的ext目錄中,這裡存放着各個擴展模塊的源代碼,選擇你需要的模塊,比如curl模塊:cd curl
執行phpize生成編譯文件,phpize在PHP安裝目錄的bin目錄下
/usr/local/php5/bin/phpize
運行時,可能會報錯:Cannot find autoconf. Please check your autoconf installation and
the $PHP_AUTOCONF
environment variable is set correctly and then rerun this
script.,需要安裝autoconf:
yum install autoconf(RedHat或者CentOS)、apt-get install
autoconf(Ubuntu Linux)
/usr/local/php5/bin/php -v
執行這個命令時,php會去檢查配置文件是否正確,如果有配置錯誤,
這裡會報錯,可以根據錯誤信息去排查!
原創文章,作者:UROY,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/146906.html