예제 #1
0
 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;
 }
예제 #2
0
파일: apiv1.php 프로젝트: eric116/BotQueue
 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;
 }
예제 #3
0
파일: upload.php 프로젝트: eric116/BotQueue
 /**
  * @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");
     }
 }
예제 #4
0
 /**
  * @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;
 }