本文整理汇总了PHP中files::fixname方法的典型用法代码示例。如果您正苦于以下问题:PHP files::fixname方法的具体用法?PHP files::fixname怎么用?PHP files::fixname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files
的用法示例。
在下文中一共展示了files::fixname方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_edit
public function action_edit()
{
$file = ORM::factory('file', $this->request->param('id'));
if (!$file->loaded()) {
notes::add('error', 'Filen blev ikke fundet!');
cms::redirect('files');
}
if ($_POST) {
$filename = arr::get($_POST, 'filename', '');
if (empty($filename)) {
$filename = $file->filename;
}
if ($filename != $file->filename) {
$filename = files::fixname($filename);
$filename = files::get_available_filename('files/', $filename, $file->ext);
rename('files/' . $file->filename(), 'files/' . $filename . '.' . $file->ext);
$versions = $file->versions->find_all();
if ((bool) $versions->count()) {
foreach ($versions as $version) {
$version->delete();
}
}
}
$file->filename = $filename;
$file->alt = arr::get($_POST, 'alt', '');
$file->description = arr::get($_POST, 'description', '');
try {
$file->save();
cms::redirect('files/edit/' . $file->id);
} catch (exception $e) {
notes::add('error', 'Filen kunne ikke gemmes! Siden sagde: ' . $e->getMessage());
}
}
$this->bind('file', $file);
}
示例2: upload
public static function upload()
{
$dir = 'files/';
$file = $_FILES['files'];
$parts = explode('.', $file['name'][0]);
$ext = strtolower(strtolower(end($parts)));
$name = mb_strtolower(implode('.', array_slice($parts, 0, count($parts) - 1)));
$name = files::fixname($name);
$name = self::get_available_filename($dir, $name, $ext);
$filename = $name . '.' . $ext;
if (move_uploaded_file($file['tmp_name'][0], $dir . $filename)) {
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file($dir . $filename);
$mime = substr($type, 0, strpos($type, ';'));
$file = ORM::factory('File');
$file->filename = $name;
$file->type = $mime;
$file->ext = $ext;
$file->created = time();
try {
$file->save();
return $file;
} catch (exception $e) {
unlink($dir . $name);
return false;
}
} else {
return false;
}
}