public function format(array $row) { if (isset($row[$this->id]) && strlen($row[$this->id]) > 0) { $file = new \Meta\File($row[$this->id]); $label = $file->name; if ($file->exists()) { $label .= ' (' . $file->prettySize() . ')'; } return '<span class="glyphicon glyphicon-file"> </span>' . anchor($file->getDownloadPath(), $label); } return null; }
public static function generateFileName($fileName) { // check if name already exists $fileName = str_replace(' ', '_', $fileName); $newName = $fileName; $count = 1; $file = new \Meta\File($fileName); while ($file->exists()) { $lastPoint = strrpos($fileName, '.'); $newName = substr($fileName, 0, $lastPoint) . $count . substr($fileName, $lastPoint); $file = new \Meta\File($newName); $count++; } return $newName; }