示例#1
0
 /**
  * Displays the content of a zip file (id passed as arg)
  */
 public function showzipcontentAction()
 {
     $request = $this->getRequest();
     if (isset($request->id) && preg_match('/^[0-9]{1,30}$/', $request->id)) {
         $id = $request->id;
         $fileModel = new Filfiles();
         $where = "id = " . $id . " AND safinstances_id = '" . $this->safinstancesId . "' AND type = 'ZIP' ";
         $files = $fileModel->fetchAll($where);
         $this->view->ziplist = array();
         if (count($files) == 1) {
             $file = $files[0];
             //Définition dynamique du fullpath
             $fileType = $file->type;
             $fullpath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileType . '/' . $file->filename;
             $fileTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath);
             $this->view->ziplist = $fileTypeInstance->getZipContent();
         }
     }
 }
示例#2
0
 /**
  * Show small images from uploaded pictures based on it's id and type size
  *
  * Type size :
  * 2 = 64x64 pixel
  * 3 = 32x32 pixel
  * 4 = 16x16 pixel
  *
  * Example : /publicms/file/thumb/id/1/ts/2
  * where ts is the thumb size mode
  * amd id is the ID of the file to get
  */
 public function thumbAction()
 {
     $this->initFileHeaders();
     $request = $this->getRequest();
     if (isset($request->id) && preg_match('/^[0-9]{1,30}$/', $request->id)) {
         if (isset($request->ts) && preg_match('/^[0-9]{1,30}$/', $request->ts)) {
             $typeSize = $request->ts;
         } else {
             $typeSize = 1;
         }
         $elementId = $request->id;
         $fileModel = new Filfiles();
         $where = 'id = ' . $elementId . ' AND safinstances_id = ' . $this->safinstancesId;
         $result = $fileModel->fetchAll($where);
         if (count($result) == 1) {
             $file = $result[0];
             $fileType = $file->type;
             $fullpath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileType . '/' . $file->filename;
             $fileTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath);
             // defines the thumb size
             if ($typeSize == 2) {
                 $fileTypeInstance->thumbSize = array(64, 64);
             }
             if ($typeSize == 3) {
                 $fileTypeInstance->thumbSize = array(32, 32);
             }
             if ($typeSize == 4) {
                 $fileTypeInstance->thumbSize = array(16, 16);
             }
             if (!$fileTypeInstance->showThumb()) {
                 print 'Image can not be processed';
             }
         } else {
             print 'You do not have access to this information';
         }
     } else {
         print 'Something is missing...';
     }
     $this->render('index');
 }
示例#3
0
 /**
  *
  */
 public function unziptofilesAction()
 {
     // get the zip
     $r = $this->getRequest();
     if (isset($r->id) && preg_match('/^[0-9]{1,30}$/', $r->id)) {
         $id = $r->id;
         $fdb = new Filfiles();
         $where = "id = " . $id . " AND safinstances_id = '" . $this->safinstancesId . "' AND type = 'ZIP' ";
         $files = $fdb->fetchAll($where);
         $categories = $fdb->getCategoriesLabels($id);
         $ftype = null;
         if (count($files) == 1) {
             $fdb = $files[0];
             $ftype = Sydney_Medias_Filetypesfactory::createfiletype($fdb->path . '/' . $fdb->filename, $fdb);
         }
         $fullpath = Sydney_Tools_Paths::getCachePath() . '/' . uniqid('unziptofiles_');
         $this->view->content = array();
         // create the temp dir
         mkdir($fullpath);
         mkdir($fullpath . '/chunks');
         // unzip the file
         if ($ftype->unzipToDir($fullpath . '/chunks')) {
             // move the files to DB
             $fi = new Filfiles();
             $res = $fi->moveAllChuncks($fullpath, $this->usersId, $this->safinstancesId, $chunks = 'chunks', $desc = 'from zipped file - ' . $fdb->filename, $returnType = 'both');
             $this->view->content = $res[1];
             // link unzipped files to a category if any
             if (is_array($res[0]) && count($res[0]) > 0 && is_array($categories) && count($categories) > 0) {
                 $linkDB = new FilfoldersFilfiles();
                 foreach ($res[0] as $fileId) {
                     foreach ($categories as $categoryId => $catlabel) {
                         $row = $linkDB->createRow();
                         $row->filfolders_id = $categoryId;
                         $row->filfiles_id = $fileId;
                         $row->save();
                     }
                 }
             }
             // remove temp dir
             Sydney_Tools_Dir::rrmdir($fullpath);
         }
     }
 }
示例#4
0
 /**
  *
  */
 public function scaleAction()
 {
     $re = $this->getRequest();
     $image = $this->_getImageFromRequest();
     if ($image) {
         //Définition dynamique du fullpath
         $webinstanceName = $this->_config->general->webinstance;
         $imageType = $image->type;
         $fullpath = __DIR__ . '/../../../../../webinstances/' . $webinstanceName . '/appdata/adminfiles/' . $imageType . '/' . $image->filename;
         $imageTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath);
         if (!$imageTypeInstance->scale($re->val)) {
             print 'Image can not be processed';
         }
     }
     $this->render('index');
 }
示例#5
0
 /**
  * Move a file from a directory to the final appdata of the webinstance
  * and register it to the DB
  *
  * @param string $filepath Path to the temp files
  * @param string $comment Comment to place in the meta description (for search purpose, for ex the name of the user)
  * @param string $folder The name of the folder to push the files in
  * @return bool|int
  */
 public function fileToFileManager($filepath = '', $comment = '', $folder = 'temp')
 {
     if (!file_exists($filepath)) {
         return false;
     }
     try {
         $fileObj = Sydney_Medias_Filetypesfactory::createfiletype($filepath);
         $newName = uniqid() . '_' . Sydney_Medias_Utils::sanitizeFilename($fileObj->basename . '.' . $fileObj->extension);
         $newPath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $fileObj->extension . '/';
         if (!is_dir($newPath)) {
             mkdir($newPath, 0777, true);
         }
         rename($filepath, $newPath . $newName);
         $fileName = $newName;
         $newFileObj = Sydney_Medias_Filetypesfactory::createfiletype($newPath . $newName);
         $fileInfo = $newFileObj->getFileinfo();
         $fileWeight = $fileInfo['general.filesize'];
         // On récupère la taille du fichier pour pouvoir l'ajouter en DB
         $type = $newFileObj->extension;
         $usersId = Sydney_Tools_User::getUserdata('users_id');
         // @todo TODO we ll have to change that, for now it uploads the file as Arnaud (user id 1) if nothing is defined.
         if ($usersId === false) {
             $usersId = 1;
         }
         $safinstancesId = Sydney_Tools_Sydneyglobals::getSafinstancesId();
         // save the file to DB
         $fileFilesId = $this->registerFileToDb($newPath, $fileName, $fileWeight, $type, $usersId, $safinstancesId, array(), $comment);
         // put them in the right folder
         $filefoldersDb = new Filfolders();
         $filefoldersId = $filefoldersDb->addSystemFolder($folder);
         if ($fileFilesId) {
             $fileCorDb = new FilfoldersFilfiles();
             $fileCor = $fileCorDb->createRow();
             $fileCor->filfolders_id = $filefoldersId;
             $fileCor->filfiles_id = $fileFilesId;
             $fileCor->save();
         }
         // returns the files ids
         return $fileFilesId;
     } catch (Exception $e) {
         Zend_Debug::dump($e->getMessage());
         return false;
     }
 }