<?php $filename = ‘/mnt/hgfs/workspace/weituibao/app/config/../../public/files/36/temp/201410/21/1413873853598.jpg‘; function getRealPath($filename, $split = ‘/‘) { while(true) { if (FALSE === strpos($filename, $split . ‘.‘)) { break; } $filename = explode($split, $filename); foreach($filename as $k => $f) { if (($k && $f == ‘‘) || $f == ‘.‘) { unset($filename[$k]); break; } elseif ($f == ‘..‘) { unset($filename[$k]); if(isset($filename[$k-1])) unset($filename[$k-1]); break; } } $filename = implode($split, $filename); } return $filename; } echo getRealPath($filename);
---------- php ----------
/mnt/hgfs/workspace/weituibao/public/files/36/temp/201410/21/1413873853598.jpg
输出完成 (耗时 0 秒) - 正常终止
时间: 2024-10-10 02:51:21