/** * 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(); } } }
/** * Delete a file with the ID passed as param. * URL example : http://<url>/adminfile/services/deletefiles/format/json/id/5 * @return the result in the format requested */ public function deletefileAction() { $r = $this->getRequest(); $this->view->ResultSet = array('status' => 0, 'message' => 'Undefined Error ' . $r->id); if (isset($r->id)) { $id = $r->id; $fdb = new Filfiles(); $where = 'id = ' . $id . ' AND safinstances_id = ' . $this->safinstancesId; $files = $fdb->fetchAll($where); if (count($files) == 1) { $f = $files[0]; if (Sydney_Search_Files_Links::getInstance()->isLinked($id)) { $this->view->ResultSet = array('status' => 0, 'message' => 'The file has linked into content and could not be delete from the database.'); $this->view->ResultSet['showtime'] = 5; } elseif ($fdb->delete($where)) { /* * GDE : 27/08/2010 * Add trace of current action */ Sydney_Db_Trace::add('trace.event.delete_file' . ' [' . $f->filename . ']', 'adminfiles', Sydney_Tools::getTableName($fdb), 'deletefile', $id); // */ $fullpath = Sydney_Tools_Paths::getAppdataPath() . '/adminfiles/' . $f->type . '/' . $f->filename; if (unlink($fullpath)) { $this->view->ResultSet = array('status' => 1, 'message' => 'File ' . $f->label . ' deleted', 'modal' => false); } else { $this->view->ResultSet = array('status' => 0, 'message' => 'The file could not be delete on the hard disk.'); $this->view->ResultSet['showtime'] = 5; } } else { $this->view->ResultSet = array('status' => 0, 'message' => 'The file could not be delete from the database.'); $this->view->ResultSet['showtime'] = 5; } } } }
/** * 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'); }
/** * 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; } }