本文整理汇总了PHP中files::randomname方法的典型用法代码示例。如果您正苦于以下问题:PHP files::randomname方法的具体用法?PHP files::randomname怎么用?PHP files::randomname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类files
的用法示例。
在下文中一共展示了files::randomname方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: upload
public function upload($files, $limits = array())
{
$parts = explode('.', $files['name'][0]);
$orgfilename = $files['name'][0];
$size = $files['size'][0];
$this->ext = strtolower(strtolower(end($parts)));
if ($this->allowed_exts != false && !in_array($this->ext, $this->allowed_exts)) {
// Illegal file extention
throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades. <strong>Filtypen er ikke tilladt</strong>. Kun billeder af følgende filtyper er tilladt: ' . implode(', ', $this->allowed_exts));
}
if ($this->maxsize != false && (!$size || $size == 0 || $size > $this->maxsize)) {
// Too big
throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades da den er for stor! Filer må højest være ' . files::format_bytes($this->maxsize));
}
if ($this->require_login && !user::logged()) {
// We only accept files from logged in users
throw new Exception_User('Du skal være logget ind for at uploade filer. Tjek at du er logget ind og forsøg igen.');
}
$this->filename = files::randomname() . '.' . $this->ext;
$i = 2;
while (file_exists($this->path . $this->filename)) {
$this->filename = files::randomname() . '.' . $this->ext;
}
try {
move_uploaded_file($files['tmp_name'][0], $this->path . $this->filename);
// Should throw an exception if it fails
$finfo = new finfo(FILEINFO_MIME);
$type = $finfo->file($this->path . $this->filename);
$mime = substr($type, 0, strpos($type, ';'));
if ($this->allowed_mimes != false && !in_array($mime, $this->allowed_mimes)) {
// Illegal file mime
throw new Exception_File('Filen "' . $orgfilename . '" kunne ikke uploades. <strong>Filtypen er ikke tilladt</strong>. Kun billeder af følgende filtyper er tilladt: ' . implode(', ', $this->allowed_exts));
}
if ($this->require_login) {
$this->user_id = user::get()->id;
}
$this->type = $mime;
$this->created = time();
$this->save();
return $this;
} catch (exception $e) {
// File move failed. Maybe log the error?
if (file_exists($this->path . $this->filename)) {
unlink($this->path . $this->filename);
}
throw $e;
}
}