/** * */ public function saveimageAction() { $image = $this->_getImageFromRequest(); if ($image) { //Définition dynamique du fullpath $webinstanceName = $this->_config->general->webinstance; $imageType = $image->type; $path = __DIR__ . '/../../../../../webinstances/' . $webinstanceName . '/appdata/adminfiles/' . $imageType . '/'; $fullpath = $path . $image->filename; $imageTypeInstance = Sydney_Medias_Filetypesfactory::createfiletype($fullpath); $im = $imageTypeInstance->_getTempEditorFullPath(); $bn = preg_split('/\\./', basename($fullpath)); $filename = $bn[0] . '-' . mktime() . '.' . $bn[1]; rename($im[1], $path . $filename); $fweight = filesize($path . $filename); $fil = new Filfiles(); $fil->registerFileToDb($path, $filename, $fweight, strtoupper($bn[1]), $this->usersId, $this->safinstancesId); $this->view->message = 'Image saved to ' . $filename; } else { $this->view->message = 'Could not save the image...'; } }
/** * Displays the upload screen * @return void */ public function uploadAction() { //$this->_helper->layout->disableLayout(); $params = $this->getRequest()->getParams(); // gets the categories for upload + tagging $catDB = new Filfolders(); $this->view->categories = $catDB->getFoldersStructure(); if ($params['calledBy'] != 'adminpeople') { $this->setSubtitle('Upload files'); $this->setSideBar('upload', 'files'); } if (count($_FILES['file']) > 0) { switch ($_FILES['file']['error']) { case UPLOAD_ERR_OK: $fullpath = Sydney_Tools::getAppdataPath() . '/adminfiles/'; $filename = $_FILES['file']['name']; $ndirn = substr($filename, -3); $ndirn = preg_replace('/\\./', '', $ndirn); $nnd = $fullpath . '/' . strtoupper($ndirn); $type = strtoupper($ndirn); if (!is_dir($nnd)) { mkdir($nnd); } if (!empty($_POST['fileupload-new-filename'])) { $filename = $_POST['fileupload-new-filename']; } if (move_uploaded_file($_FILES['file']['tmp_name'], $nnd . '/' . $filename)) { $fil = new Filfiles(); $fil->registerFileToDb($nnd, $filename, filesize($nnd . '/' . $filename), $type, $this->usersId, $this->safinstancesId, $this->getRequest()); $returnmsg = '"' . $filename . '", ' . Sydney_Tools::_('UPLOAD_ERR_OK'); } else { $returnmsg = Sydney_Tools::_('UPLOAD_UNKNOW_ERROR'); } break; case UPLOAD_ERR_INI_SIZE: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_INI_SIZE'); break; case UPLOAD_ERR_FORM_SIZE: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_FORM_SIZE'); break; case UPLOAD_ERR_PARTIAL: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_PARTIAL'); break; case UPLOAD_ERR_NO_FILE: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_NO_FILE'); break; case UPLOAD_ERR_NO_TMP_DIR: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_NO_TMP_DIR'); break; case UPLOAD_ERR_CANT_WRITE: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_CANT_WRITE'); break; case UPLOAD_ERR_EXTENSION: $returnmsg = Sydney_Tools::_('UPLOAD_ERR_EXTENSION'); break; } if (!empty($returnmsg)) { echo '<span class="warning">', $returnmsg, '</span>'; } } }
/** * Register the file and location in the DB for quick search and indexing * * @return void * @param string $path Path to the file * @param string $fileName File name on the hard disk * @param int $fileWeight Weight in bytes * @param string $type 3 letters extension */ private function _registerFileToDb($path, $fileName, $fileWeight, $type, $params = array()) { $fil = new Filfiles(); $fil->registerFileToDb($path, $fileName, $fileWeight, $type, $this->usersId, $this->safinstancesId, $params); }