public function __construct(array $args = array()) { $this->setByArray(static::$defaults, $args); if ($this->gallery && !$this->folder) { $this->folder = $this->gallery->folder; } $this->setMemToken(); if (!$this->folder) { throw new \Exception('Uploader requires a folder.'); } if (!is_object($this->folder)) { $this->folder = Client::getFolder($this->folder); } if (!$this->folder->path) { // don't throw exception if the folder doesn't exist. -will //throw new \Exception('Could not get folder object from server.'); } $this->getHTML(); }
/** * Does the upload if there are no errors, and uploads the db_field if necessary * @return array response array */ public function doUpload() { if ($this->errors) { return $this->respond(); } $upload_opts = array('folder' => $this->folders_path); $re = Client::getClient()->addItem($upload_opts, $this->uploaded_file); unlink($this->uploaded_file); // delete file from tmpdir if ($re->errors) { $this->errors[] = 'There was an error uploading the file:'; $this->errors = array_merge($this->errors, array_map(function ($e) { return $e->message; }, $re->errors)); return $this->respond($re); } if ($this->params['db_field'] && $this->params['db_row_id']) { $this->updateDBRecord($re->item->id); } $folder = Client::getFolder($this->folders_path); // update the last upload time so we know when to refresh cached folders $memkey = "vf2:getFolder:lastUpload:" . $this->folders_path; mem($memkey, date('U')); $memkey = "vf2:getFolder:lastUpload:" . $folder->id; mem($memkey, date('U')); return $this->respond($re); }