<?php
namespace Moto\Filter; use Zend\Filter\Exception; class RelativePath extends AbstractFilter { public function filter($value) { if (!is_string($value)) { return uniqid('file_'); } $value = str_replace('..', '', $value); if (!preg_match("/^[a-z0-9_\-]+\.[a-z0-9]+$/i", basename($value)) || basename($value) != ltrim(substr($value, strrpos($value, DIRECTORY_SEPARATOR) ), DIRECTORY_SEPARATOR) ) { $dirname = trim(str_replace('\\', '/', dirname($value)), './'); if (!empty($dirname)) { $dirname .= '/'; } $value = $dirname . str_replace(' ', '_', basename($value)); } return $value; } }