public function getFileCollection($where) { global $dRep; $where = $this->sqlBuilder->createWhere($where, ''); $sql = "SELECT * FROM ink_files WHERE {$where};"; $data = $this->runManyQuery($sql); $files = array(); foreach ($data as $index => $row) { $file = new File(); $properties = array('id' => $row['fileId'], 'siteId' => $row['siteId'], 'filename' => $row['filename'], 'folderId' => $row['folderId'], 'size' => $row['filesize'], 'type' => $dRep->getFiletype($row['filetypeId']), 'timestamp' => $row['uploaded']); $file->setProperties($properties); // $file = $this->getFiletext($file); $this->fileCache[$file->getId()] = $file; $files[] = $file; } return $files; }
public function savefile($path = '') { global $varChecker; $return = true; if ($path == '') { $return = false; $path = $varChecker->getValue('filepath'); } if (empty($path) || !$path) { throw new DataException('missingpath'); } $extension = substr($path, strrpos($path, '.')); $file = new File(); $filetype = $this->dRep->getFiletype(str_replace('.', '', $extension)); if ($filetype->getId() == 'new') { throw new DataException('nofiletype'); } $folder = $this->getCurrentFolder(); $properties = array('filename' => trim(substr($path, strrpos($path, '/')), '/'), 'type' => $filetype, 'folderId' => $folder->getId(), 'filesize' => filesize($path)); try { $file->setProperties($properties); $file = $this->dRep->saveFile($file); //after saving file, we need to upload it to client server $connection = new HTTPUploader($this->INK_User->getCustomer()->getSite()); $isUploaded = $connection->uploadFile($file, $path); if ($isUploaded !== true) { $result = array('fileid' => $file->getId(), 'error' => 'file_notuploaded', 'msg' => $isUploaded); $this->dRep->delFile($file); } else { $result = array('fileid' => $file->getId(), 'success' => 'file_saved'); } } catch (Exception $ex) { $result = array('error' => $ex->getMessage()); } if ($return) { return $result; } else { echo json_encode($result); } }