当前位置: 首页>>代码示例>>PHP>>正文


PHP files::randomname方法代码示例

本文整理汇总了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;
     }
 }
开发者ID:artbypravesh,项目名称:morningpages,代码行数:48,代码来源:File.php


注:本文中的files::randomname方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。