In general, get similar test.txt, test.html, test.png and other extensions are fine.
such as Test.png.txt, the problem is not very big, because we can think. png is a file name instead of an extension
But what if it's test.tar.gz? White list?
Reply content:
In general, get similar test.txt, test.html, test.png and other extensions are fine.
such as Test.png.txt, the problem is not very big, because we can think. png is a file name instead of an extension
But what if it's test.tar.gz? White list?
The file name suffix should standardize test.tar.gz. Tar is a packaged file. GZ is a compressed file
Linux compressed files are very canonical
TEST.TAR.GZ gzip Compressed tar packaging
TEST.GZ gzip compressed, not packaged
TEST.TAR.BZ2 BUNZIP2 Compressed Tar Package
TEST.BZ2 BUNZIP2 Compressed not packaged
In the programming world, only the underlying operations can be constrained to achieve graceful upper-level code. If a file is in% as a file suffix
If my interface is designed like this,
class fileInfo(){ public function reFileName(); #文件名 public function getRealSuffix(); #最后一个 test.tar.gz 返回gz public function getFullSuffix(); #全部后缀test.tar.gz 返回tar.gz public function getSuffixs(); #后缀名数组}
File formats can be restricted, matched by known suffixes
The extension can be obtained in this way
$info = pathinfo($file);echo $info['extension'];
In fact, you want to do file type filtering, it is recommended to use mimetype instead of extension, more reliable.
Reference http://php.net/manual/zh/book.fileinfo.php can be used directly from the php5.3.