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


PHP Uploader::getExtension方法代码示例

本文整理汇总了PHP中Uploader::getExtension方法的典型用法代码示例。如果您正苦于以下问题:PHP Uploader::getExtension方法的具体用法?PHP Uploader::getExtension怎么用?PHP Uploader::getExtension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Uploader的用法示例。


在下文中一共展示了Uploader::getExtension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: uploadImage

 public static function uploadImage()
 {
     $allowFile = array("image/jpeg", "image/png", "image/gif");
     $df = "Ymd-H-i-s";
     $fileName = "TMPIMG" . date($df) . "." . Uploader::getExtension();
     if (!Uploader::getTempFile()) {
         $result['error'] = true;
         $result['message'] = 'Please browse for a file!';
         echo json_encode($result);
         return;
     }
     if (!in_array(Uploader::getType(), $allowFile)) {
         $result['error'] = true;
         $result['message'] = 'Please choose only image file (jpg, png or gif)!';
         echo json_encode($result);
         return;
     }
     if (Uploader::moveUploadFileTo(self::$tmpDir, $fileName)) {
         $result['error'] = false;
         $result['message'] = 'File upload succeeded!';
         $result['image'] = 'assets/upload/tmp/' . $fileName;
         $result['alt'] = $fileName;
     } else {
         $result['error'] = true;
         $result['message'] = 'Fail in moving file upload!';
     }
     echo json_encode($result);
 }
开发者ID:midmike,项目名称:h0001pre,代码行数:28,代码来源:FoodControl.php

示例2: save

 public function save()
 {
     $dgClass = new dg();
     if (!empty($_POST)) {
         $art = $_POST['art'];
         if (isset($_FILES["file"]["name"]) && $_FILES["file"]["name"] != '') {
             // create folder
             $root = dirname(ROOT) . DS . 'uploaded' . DS . 'cliparts' . DS . $art['cate_id'];
             if (!file_exists($root)) {
                 mkdir($root, 0755, TRUE);
             }
             $upload_path = $root . DS . 'print' . DS;
             if (!is_dir($upload_path)) {
                 mkdir($upload_path, 0755, TRUE);
             }
             // upload file
             require_once dirname(ROOT) . DS . 'includes' . DS . 'upload.php';
             $uploader = new Uploader();
             $uploader->setDir($upload_path);
             $uploader->setExtensions(array('jpg', 'jpeg', 'png', 'gif', 'svg'));
             $uploader->setMaxSize(10);
             $uploader->sameName(false);
             if ($uploader->uploadFile('file')) {
                 $image = $uploader->getUploadName();
                 $extension = $uploader->getExtension($image);
                 $extension = strtolower($extension);
                 $url = site_url('uploaded/cliparts/');
                 $url = str_replace('/admin/', '/', $url);
                 $art['file_type'] = $extension;
                 $art['file_name'] = $image;
                 $art['path'] = $url;
                 $art['url'] = $url . $art['cate_id'] . '/';
                 // create folder thumb
                 $thumbs = $root . DS . 'thumbs';
                 if (!is_dir($thumbs)) {
                     mkdir($thumbs, 0755, TRUE);
                 }
                 $medium = $root . DS . 'medium';
                 if (!is_dir($medium)) {
                     mkdir($medium, 0755, TRUE);
                 }
                 if ($extension == 'svg') {
                     $art['change_color'] = 1;
                     $art['thumb'] = 'print/' . $image;
                     $art['medium'] = 'print/' . $image;
                 } else {
                     require_once ROOT . DS . 'includes' . DS . 'thumb.php';
                     $thumb = new thumb($upload_path . $image);
                     $thumb->resize(null, 100, 100, $thumbs . DS . md5($image) . '.' . $extension);
                     $thumb->resize(null, 300, 300, $medium . DS . md5($image . 'medium') . '.' . $extension);
                     $art['thumb'] = 'thumbs/' . md5($image) . '.' . $extension;
                     $art['medium'] = '/medium/' . md5($image . 'medium') . '.' . $extension;
                     $art['change_color'] = 0;
                 }
             } else {
                 echo $uploader->getMessage();
             }
         }
         $art['price'] = (double) $art['price'];
         $file = dirname(ROOT) . DS . 'data' . DS . 'arts.json';
         // check file
         if (!file_exists($file)) {
             $dgClass->redirect('index.php/clipart');
             return;
         }
         $data = file_get_contents($file);
         $arts = json_decode($data);
         $is_new = true;
         $conent = array();
         if (isset($_POST['id']) && $_POST['id'] > 0) {
             $id = $_POST['id'];
             // update clipart
             if (isset($arts->arts) && count($arts->arts) > 0) {
                 foreach ($arts->arts as $row) {
                     if ($row->clipart_id == $id) {
                         $art['clipart_id'] = $id;
                         $conent[] = $art;
                         $is_new = false;
                     } else {
                         $conent[] = $row;
                     }
                 }
             }
         }
         if ($is_new === true) {
             $index = 0;
             foreach ($arts->arts as $row) {
                 if ($row->clipart_id > $index) {
                     $index = $row->clipart_id;
                 }
                 $conent[] = $row;
             }
             $art['clipart_id'] = $index + 1;
             $conent[] = $art;
             $arts->count = $arts->count + 1;
         }
         $arts->arts = $conent;
         $dgClass->WriteFile($file, json_encode($arts));
         $dgClass->redirect('index.php/clipart');
     } else {
//.........这里部分代码省略.........
开发者ID:rootcave,项目名称:9livesprints-web,代码行数:101,代码来源:clipart.php


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