Exemplo n.º 1
0
 /**
  * Saves files posted in the forms classifyFileList function
  */
 public function classifyFiles()
 {
     PHPWS_Core::initModClass('filecabinet', 'Image.php');
     PHPWS_Core::initModClass('filecabinet', 'Document.php');
     PHPWS_Core::initModClass('filecabinet', 'Multimedia.php');
     if (empty($_POST['file_count'])) {
         return false;
     }
     foreach ($_POST['file_count'] as $key => $filename) {
         $folder_id = $_POST['folder'][$key];
         $folder = new Folder($folder_id);
         if (empty($_POST['file_title'][$key])) {
             $error[$filename] = dgettext('filecabinet', 'Missing title.');
         }
         // initialize a new file object
         switch ($folder->ftype) {
             case IMAGE_FOLDER:
                 $file_obj = new PHPWS_Image();
                 break;
             case DOCUMENT_FOLDER:
                 $file_obj = new PHPWS_Document();
                 break;
             case MULTIMEDIA_FOLDER:
                 $file_obj = new PHPWS_Multimedia();
                 break;
         }
         // save the folder id and basic information
         $file_obj->folder_id = $folder->id;
         $file_obj->setFilename($filename);
         $file_obj->setTitle($_POST['file_title'][$key]);
         $file_obj->setDirectory($folder->getFullDirectory());
         if (!empty($_POST['file_description'][$key])) {
             $file_obj->setDescription($_POST['file_description'][$key]);
         }
         // move the file from the incoming directory
         $classify_dir = $this->getClassifyDir();
         if (empty($classify_dir)) {
             return array(dgettext('filecabinet', 'The web server does not have permission to access files in the classify directory.'));
         }
         $incoming_file = $classify_dir . $filename;
         $folder_directory = $file_obj->getPath();
         if (!@rename($incoming_file, $folder_directory)) {
             $errors[$filename] = sprintf(dgettext('filecabinet', 'Could not move file "%s" to "%s" folder directory.'), $filename, $folder->title);
             PHPWS_Error::log(FC_FILE_MOVE, 'filecabinet', 'Cabinet::classifyFiles', $folder_directory);
             continue;
         }
         $file_obj->file_type = PHPWS_File::getMimeType($file_obj->getPath());
         $file_obj->loadFileSize();
         // if image is getting saved, need to process
         if ($folder->ftype == IMAGE_FOLDER) {
             $file_obj->loadDimensions();
             $file_obj->save(true, false);
         } else {
             $file_obj->save(false);
         }
     }
     if (isset($errors)) {
         return $errors;
     } else {
         return true;
     }
 }
Exemplo n.º 2
0
 private function saveFile(\Request $request)
 {
     switch ($request->getVar('ftype')) {
         case DOCUMENT_FOLDER:
             PHPWS_Core::initModClass('filecabinet', 'Document.php');
             $doc = new PHPWS_Document($request->getVar('file_id'));
             $doc->setTitle($request->getVar('title'));
             $doc->save(false);
             break;
         case IMAGE_FOLDER:
             PHPWS_Core::initModClass('filecabinet', 'Image.php');
             $img = new PHPWS_Image($request->getVar('file_id'));
             $img->setTitle($request->getVar('title'));
             $img->save(false, false, false);
             break;
         case MULTIMEDIA_FOLDER:
             PHPWS_Core::initModClass('filecabinet', 'Multimedia.php');
             $mm = new PHPWS_Multimedia($request->getVar('file_id'));
             $mm->setTitle($request->getVar('title'));
             $mm->save(false, false);
             break;
     }
 }