Exemple #1
0
 public function local()
 {
     // Local file upload
     try {
         if (empty($_FILES['file']) || !is_uploaded_file($_FILES['file']['tmp_name'])) {
             throw new Exception("Something went wrong with uploading this file. The file may be too large to upload.");
         }
         $tmp_file = $_FILES['file'];
         $dst = STORAGE_PATH . "/uploads/" . $tmp_file["name"];
         $this->ensureGoodFile($tmp_file);
         if (file_exists($dst)) {
             unlink($dst);
         }
         // Create the directory structure if it doesn't exist
         if (!is_dir(dirname($dst))) {
             mkdir(dirname($dst), 0777, true);
         }
         rename($tmp_file["tmp_name"], $dst);
         $file = FileUploadHandler::fromName("uploads/" . $tmp_file["name"]);
         Activity::log("uploaded a new file called " . $file->getLink() . ".");
         //send us to step 2.
         $this->forwardToUrl("/job/create/file:{$file->id}");
     } catch (Exception $e) {
         $this->set('megaerror', $e->getMessage());
     }
 }
 public function get_image_size($paths, $auto_orient = TRUE, $force_array = FALSE)
 {
     if (is_string($paths)) {
         $path_array = preg_split('/(;|\\s)/', $paths, -1, PREG_SPLIT_NO_EMPTY);
         $is_array = FALSE;
     } else {
         if (is_array($paths)) {
             $path_array = $paths;
             $is_array = TRUE;
         } else {
             return NULL;
         }
     }
     $handler = new FileUploadHandler($this->_options(array()), FALSE);
     $current_host = parse_url(base_url(), PHP_URL_HOST);
     $new_path_array = array();
     foreach ($path_array as $path) {
         $path_host = parse_url($path, PHP_URL_HOST);
         if ($path_host && $current_host !== $path_host) {
             $new_path_array[] = $path;
         } else {
             $new_path_array[] = ltrim(stripslashes(parse_url($path, PHP_URL_PATH)), '/');
         }
     }
     if ($force_array || $is_array) {
         $result = array();
         foreach ($new_path_array as $path) {
             $result[] = @$handler->get_image_size($path, $auto_orient);
         }
     } else {
         $result = @$handler->get_image_size($new_path_array[0], $auto_orient);
     }
     return $result;
 }
Exemple #3
0
 /**
  * @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");
     }
 }
Exemple #4
0
 public function success()
 {
     $this->assertLoggedIn();
     //handle our upload
     try {
         $file = FileUploadHandler::fromName($this->args('key'));
         Activity::log("uploaded a new file called " . $file->getLink() . ".");
         //send us to step 2.
         $this->forwardToUrl("/job/create/file:{$file->id}");
     } catch (Exception $e) {
         $this->setTitle("Upload File - Error");
         $this->set('megaerror', $e->getMessage());
     }
 }