Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
PHP: filetype - Manual
[go: Go Back, main page]

PHP
downloads | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

flock" width="11" height="7"/> <filesize
Last updated: Sun, 25 Nov 2007

view this page in

filetype

(PHP 4, PHP 5)

filetype — ファイルタイプを取得する

説明

string filetype ( string $filename )

指定したファイルのタイプを返します。

パラメータ

filename

ファイルへのパス。

返り値

ファイルのタイプを返します。返される値は fifo、char、dir、 block、link、file、socket および unknown のいずれかです。

エラーが発生すると FALSE を返します。 また filetype() は stat コールに失敗したり、 未知のファイルタイプであったりした場合に E_NOTICE メッセージを発行します。

Example#1 filetype() の例

<?php

echo filetype('/etc/passwd');  // ファイル
echo filetype('/etc/');        // ディレクトリ

?>

注意

注意: この関数の結果は キャッシュされます。詳細は、clearstatcache() を参照してください。

ヒント

PHP 5.0.0 以降、この関数は、 何らかの URL ラッパーと組合せて使用することができます。 どのラッパーが stat() ファミリーをサポートしているか のリストについては、サポートされるプロトコル/ラッパー を参照してください。



flock" width="11" height="7"/> <filesize
Last updated: Sun, 25 Nov 2007
 
add a note add a note User Contributed Notes
filetype
rich dot fleming at NOSPAM dot gmail dot com
26-Feb-2008 12:08
In response to zachary.s.scott[at]gmail[dot]com.

A simplified method would be to pop the last element off the array as that one will be your extension.

<?php
    $file
= "/some/path/to/your.file_stored_here.txt";
   
$extension = array_pop(explode(".", $file));
?>

$extension = 'txt'

you could further use this with basename to strip off the extension completely off the file...

<?php
    $file
= "/some/path/to/your.file_stored_here.txt";
   
$extension = array_pop(explode(".", $file));
   
$filename = basename($file, ".$extension");
?>

$extension = 'txt'
$filename = 'your.file_stored_here'
zachary.s.scott[at]gmail[dot]com
14-Jan-2008 01:15
I find that if you're trying to get the extension of a file, this method isn't the what you want. I've written a function instead:

<?php
function fileExtension($file) {
   
$fileExp = explode('.', $file); // make array off the periods
   
$filetype = $fileExp[count($fileExp) -1]; // file extension will be last index in array, -1 for 0-based indexes
}
?>
ruach at chpc dot utah dot edu
11-Mar-2004 10:11
There are 7 values that can be returned. Here is a list of them and what each one means

block: block special device

char: character special device

dir: directory

fifo: FIFO (named pipe)

file: regular file

link: symbolic link

unknown: unknown file type

flock" width="11" height="7"/> <filesize
Last updated: Sun, 25 Nov 2007
 
 
show source | credits | sitemap | contact | advertising | mirror sites