Example #1
0
 /**
  * Create a file instance from a file info array ($_FILES)
  * 
  * @param array $fileInfo
  *
  * @return File The created file
  */
 public static function createFromArray(array $fileInfo)
 {
     $file = new File();
     $file->setName(isset($fileInfo['name']) ? $fileInfo['name'] : null);
     $file->setSize(isset($fileInfo['size']) ? $fileInfo['size'] : 0);
     $file->setType(isset($fileInfo['type']) ? $fileInfo['type'] : null);
     $file->setTmpName(isset($fileInfo['tmp_name']) ? $fileInfo['tmp_name'] : null);
     $file->setError(isset($fileInfo['error']) ? $fileInfo['error'] : 0);
     return $file;
 }
Example #2
0
 /**
  * Default factory for uploaded files
  * @param string $field
  * @param array $input
  * @return \qio\File\Upload\File
  */
 public function getFile($field, array $input)
 {
     $file = new File();
     $file->setFieldName($field);
     $file->setOriginalName($input['name']);
     $file->setTemporaryName($input['tmp_name']);
     $file->setMimeType($input['type']);
     $file->setSize($input['size']);
     $file->setErrorCode($input['error']);
     return $file;
 }
 public function save_file_data($file_name, $file_type, $file_size, $file_path)
 {
     $file_entity = new File();
     $base = new Base();
     $file_entity->setName($file_name);
     $file_entity->setSize($file_size);
     $file_entity->setType($file_type);
     $file_entity->setPath($file_path);
     $base->audit_fields($file_entity, 'create');
     $file_entity->save();
 }
 /**
  * Get File Revisions
  *
  * @param fileId - required -
  *		The id of the file.
  *
  * @return 	A File object is return with all the revisions
  * or the error code and message returned by the server.
  */
 public function getFileRevisions($fileId)
 {
     $urld = 'dpi/v1/folder/file/' . $fileId . '/revisions';
     $parameters = array();
     $this->response = $this->restTransportInstance->sendRequest($urld, $parameters, self::HTTP_GET, $this->authToken);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new File();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         $errorStatus = $responseBody->errorStatus;
         if (empty($errorStatus)) {
             $returnObject->setRevision((string) $responseBody->attributes()->revision);
             $returnObject->setId((string) $responseBody->attributes()->id);
             $returnObject->setStatus((string) $responseBody->status);
             $returnObject->setCreatedOn((string) $responseBody->createdOn);
             $returnObject->setName((string) $responseBody->name);
             $returnObject->setOwnedByStorage((string) $responseBody->ownedByStorage);
             $returnObject->setParentId((string) $responseBody->parentid);
             $returnObject->setRevisionCount((string) $responseBody->revisionCount);
             $returnObject->setSize((string) $responseBody->size);
             $revisions = array();
             $revisionsTag = (string) $responseBody->revisions->count();
             if ($revisionsTag > 0) {
                 foreach ($responseBody->revisions->children() as $currentRevision) {
                     if ($currentRevision->count() > 0) {
                         $revision = new Revision();
                         $revision->setId((string) $currentRevision->attributes()->id);
                         $revision->setCurrent((string) $currentRevision->current);
                         $revision->setDownloadUrl((string) $currentRevision->downloadUrl);
                         $revision->setSize((string) $currentRevision->size);
                         array_push($revisions, $revision);
                     }
                 }
                 $returnObject->setRevisions($revisions);
             }
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }
Example #5
0
if (get_debug()) {
    var_dump($data);
}
// loop through messages
foreach ($data->files as $item) {
    // check if has been successfully downloaded
    if ($item->status >= 4) {
        // check if file already exists
        $file = FileQuery::create()->filterByHash($item->hash)->findOne();
        if (!$file) {
            // put file information into data base
            $file = new File();
            $file->setHash($item->hash);
            $file->setSuffix($item->suffix);
            $file->setDescription($item->description);
            $file->setSize($item->size);
            $file->setTime($item->time);
            $file->setStatus($item->status);
            $file->save();
            // advertise this file via twitter
            // TODO: send images < 3MB directly to twitter
            $txt = $file->getDescription() . " " . twitter_file_link($file);
            twitter_send2twitter($txt);
            if (get_debug()) {
                echo "advertised file on twitter: {$txt}\n";
            }
        }
    } else {
        if ($item->status == -2) {
            // delete file
            $file = FileQuery::create()->filterByHash($item->hash)->delete();
Example #6
0
 /**
  * @param array $params
  * @return string
  */
 public function createFile($params)
 {
     if (isset($params['folder-id'])) {
         $folder = $this->fs->loadFolder($params['folder-id']['value']);
         if ($folder) {
             $file = new File();
             $file->setCreatedTime(new \DateTime());
             if (isset($params['file-name'])) {
                 $file->setName($params['file-name']['value']);
             }
             if (isset($params['file-size'])) {
                 $file->setSize($params['file-size']['value']);
             }
             try {
                 $file = $this->fs->createFile($file, $folder);
                 return 'New file with id: ' . $file->getId() . ' created successfully in folder with id ' . $folder->getId();
             } catch (\Exception $ex) {
                 return $ex->getMessage();
             }
         } else {
             return 'Specified Folder ID doesn\'t exist in database';
         }
     } else {
         return 'Folder ID was not specified';
     }
 }
Example #7
0
 /**
  * setSize() should throw InvalidArgumentException if $size is not a positive integer
  */
 public function testSetSize_throwsInvalidArgumentException_ifSizeIsNotAPositiveInteger()
 {
     $this->setExpectedException('InvalidArgumentException');
     $chunker = new File();
     $chunker->setSize(-1);
     return;
 }
 /**
  * Get Item Info
  *
  * @param itemId - required -
  *         Item id
  * @return An Item object with details like itemId, expiration date, file details etc.
  * or the error code and message returned by the server.
  * 	 */
 public function getItemInfo($itemId)
 {
     $parameters = array();
     $urld = 'dpi/v1/item/' . $itemId;
     $this->response = $this->_restTransportInstance->sendRequest($urld, $parameters, 'GET', $this->_authToken);
     $responseBody = simplexml_load_string($this->response);
     $returnObject = new Item();
     if ($responseBody === false) {
         $errorCode = 'N/A';
         $errorMessage = 'The server has encountered an error, please try again.';
         $errorObject = new ErrorStatus($errorCode, $errorMessage);
         $returnObject->setErrorStatus($errorObject);
     } else {
         if (empty($responseBody->errorStatus)) {
             $create = (string) $responseBody->create;
             $returnObject->setCreate($create);
             $expiration = (string) $responseBody->expiration;
             $returnObject->setExpiration($expiration);
             $id = (string) $responseBody->id;
             $returnObject->setId($id);
             $subject = (string) $responseBody->subject;
             $returnObject->setSubject($subject);
             $message = (string) $responseBody->message;
             $returnObject->setMessage($message);
             $recipients = (string) $responseBody->recipients;
             $returnObject->setRecipients(explode(",", $recipients));
             $theFiles = array();
             $filesTag = $responseBody->file;
             if (!empty($filesTag)) {
                 foreach ($responseBody->file as $currentFile) {
                     if ($currentFile->count() > 0) {
                         $file = new File();
                         $file->setDownloadUrl((string) $currentFile->downloadUrl);
                         $file->setDownloads((string) $currentFile->downloads);
                         $file->setId((string) $currentFile->id);
                         $file->setName((string) $currentFile->name);
                         $file->setPasswordProtect((string) $currentFile->passwordProtect);
                         $file->setReturnReceipt((string) $currentFile->returnReceipt);
                         $file->setSize((string) $currentFile->size);
                         $file->setVerifyIdentity((string) $currentFile->verifyIdentity);
                         $tracking = array();
                         $trackTag = $currentFile->tracking;
                         if (!empty($trackTag)) {
                             foreach ($currentFile->tracking as $currentTrack) {
                                 if ($currentTrack->count() > 0) {
                                     $track = new Tracking();
                                     $track->setEmail((string) $currentTrack->email);
                                     $track->setWhen((string) $currentTrack->when);
                                     array_push($tracking, $track);
                                 }
                             }
                             $file->setTracking($tracking);
                         }
                         array_push($theFiles, $file);
                     }
                 }
                 $returnObject->setFiles($theFiles);
             }
         } else {
             $errorCode = (string) $responseBody->errorStatus->code;
             $errorMessage = (string) $responseBody->errorStatus->message;
             $errorObject = new ErrorStatus($errorCode, $errorMessage);
             $returnObject->setErrorStatus($errorObject);
         }
     }
     return $returnObject;
 }