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


PHP Storage::newFile方法代码示例

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


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

示例1: _handleZipFile

 public static function _handleZipFile($zip_path, $zip_file)
 {
     $za = new ZipArchive();
     $za->open($zip_path);
     for ($i = 0; $i < $za->numFiles; $i++) {
         //look up file info.
         $filename = $za->getNameIndex($i);
         //okay, is it a supported file?
         if (preg_match('/(gcode|stl|obj|amf)$/i', $filename)) {
             $temp_file = tempnam("/tmp", "BQ");
             copy("zip://" . $zip_path . "#" . $filename, $temp_file);
             //format for upload
             $filename = str_replace(" ", "_", $filename);
             $filename = preg_replace("/[^-_.[0-9a-zA-Z]/", "", $filename);
             $path = "assets/" . StorageInterface::getNiceDir($filename);
             //create our file
             $file = Storage::newFile();
             $file->set('parent_id', $zip_file->id);
             $file->set('user_id', User::$me->id);
             $file->upload($temp_file, $path);
         }
     }
     //exit;
 }
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:24,代码来源:FileUploadHandler.php

示例2: api_devicescanresults

 public function api_devicescanresults()
 {
     //$old_scan_data = json::decode($this->token->get('device_data'));
     $scan_data = json::decode($this->args('scan_data'));
     //var_dump($scan_data);
     if (!empty($_FILES)) {
         // We currently don't want to delete the old data
         //			//delete any old files if we have them.
         //			if (!empty($old_scan_data->camera_files)) {
         //				foreach ($old_scan_data->camera_files AS $id) {
         //					$data_file = Storage::get($id);
         //					$data_file->delete();
         //				}
         //			}
         foreach ($_FILES as $file) {
             if (is_uploaded_file($file['tmp_name'])) {
                 $filename = $file['name'];
                 $filename = str_replace(" ", "_", $filename);
                 $filename = preg_replace("/[^-_.[0-9a-zA-Z]/", "", $filename);
                 $this->ensureGoodFile($file);
                 //okay, we're good.. do it.
                 $data_file = Storage::newFile();
                 $data_file->set('user_id', User::$me->id);
                 $data_file->upload($file['tmp_name'], StorageInterface::getNiceDir($filename));
                 $scan_data->camera_files[] = $data_file->id;
             }
         }
     }
     //var_dump($scan_data);
     //var_dump($_FILES);
     $this->token->set('device_data', json::encode($scan_data));
     $this->token->set('last_seen', date('Y-m-d H:i:s'));
     $this->token->save();
     return True;
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:35,代码来源:apiv1.php

示例3: _handleThingiverseLinks

 /**
  * @param $url
  * @return StorageInterface
  * @throws Exception
  */
 private function _handleThingiverseLinks($url)
 {
     $matches = array();
     if (preg_match("/thingiverse.com\\/thing:([0-9]+)/i", $url, $matches)) {
         $thing_id = $matches[1];
         if (!defined('THINGIVERSE_API_CLIENT_ID') && !defined('THINGIVERSE_API_CLIENT_SECRET')) {
             throw new Exception("This site has not set up the Thingiverse api.");
         }
         $thingiverse_token = User::$me->getThingiverseToken();
         if ($thingiverse_token === '') {
             $this->forwardToURL("/thingiverse/url/" . base64_encode(serialize($url)));
         }
         $api = new ThingiverseAPI(THINGIVERSE_API_CLIENT_ID, THINGIVERSE_API_CLIENT_SECRET, User::$me->getThingiverseToken());
         //load thingiverse file
         $zip_file = $api->download_thing($thing_id);
         if ($zip_file !== null && $zip_file->isZip()) {
             $storage_file = Storage::newFile();
             $storage_file->set('user_id', User::$me->id);
             $storage_file->set('source_url', $url);
             $storage_file->uploadNice($zip_file->getFile(), $zip_file->getName());
             FileUploadHandler::_handleZipFile($zip_file->getFile(), $storage_file);
             return $storage_file;
         } else {
             throw new Exception("We can't seem to access that file");
         }
     } else {
         throw new Exception("That is not a valid Thingiverse link");
     }
 }
开发者ID:eric116,项目名称:BotQueue,代码行数:34,代码来源:upload.php

示例4: createFileForm

 /**
  * @return string
  */
 private function createFileForm()
 {
     $form = new Form('form', true);
     /** @var StorageInterface $file */
     $file = Storage::newFile();
     $fields = $file->getUploadFields();
     foreach ($fields as $name => $value) {
         $form->add(HiddenField::name($name)->value($value));
     }
     $form->add(UploadField::name("file"));
     $form->setSubmitText("Upload File");
     $form->action = $file->getUploadURL();
     return $form;
 }
开发者ID:JoonasMelin,项目名称:BotQueue,代码行数:17,代码来源:upload.php


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