Ejemplo n.º 1
0
 function uploadfileAction()
 {
     $this->disableLayout();
     //ini_set("display_errors", 1);
     $arrayErrorCode = array(UPLOAD_ERR_INI_SIZE => "UPLOAD_ERR_INI_SIZE", UPLOAD_ERR_FORM_SIZE => "UPLOAD_ERR_FORM_SIZE", UPLOAD_ERR_PARTIAL => "UPLOAD_ERR_PARTIAL", UPLOAD_ERR_NO_FILE => "UPLOAD_ERR_NO_FILE", UPLOAD_ERR_NO_TMP_DIR => "UPLOAD_ERR_NO_TMP_DIR", UPLOAD_ERR_CANT_WRITE => "UPLOAD_ERR_CANT_WRITE", UPLOAD_ERR_EXTENSION => "UPLOAD_ERR_EXTENSION", UPLOAD_ERR_EXTENSION => "UPLOAD_ERR_EXTENSION");
     sleep(3);
     $folder1 = 'eauditor';
     //strtolower($_SESSION['CollegeShortName']);
     $folder2 = str_replace("-", "", strtolower($this->_request->getParam('systemfolder', '')));
     $folderid = $this->_request->getParam('folder', '');
     // (isset($_REQUEST['folder']))? $_REQUEST['folder'] : '';
     if ($folderid == '') {
         $folderid = $this->_request->getParam('folderid', '1');
         isset($_REQUEST['folderid']) ? $_REQUEST['folder'] : '';
     }
     $file_show = $_FILES['fileupload']['name'];
     // debug($file_show)  ;
     //$fileRealname = $file_show;
     // echo $file_show;
     $file = $file_show;
     //iconv('UTF-8','TIS-620',$file_show);
     $real_name_in_db = $file;
     $url_save_in_db = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $file;
     $real_url_save_in_db = $url_save_in_db;
     $file_replace = $this->clean_filename($file);
     //$file_replace = iconv("TIS-620","UTF-8", $file_replace) ;
     // debug($file_replace)  ;
     $conn = App_Env::getDb();
     $sql = "SELECT COUNT(*) FROM sys_files WHERE FILE_REAL_NAME LIKE '{$file_show}' ";
     //debug($sql);
     $filecount = (int) $conn->fetchone($sql);
     //debug( "COUNT = ".$filecount);
     if ($filecount > 0) {
         // debug( "line 80 :filename = ".$filename);
         $fileNextIndex = $filecount + 1;
         $fileRename = $this->clean_filename($file_show, $filecount);
         $file_show = $fileRename;
         // debug( "line 90 :fileRename = ".$fileRename);
     } else {
         $fileRename = $this->clean_filename($file_show);
         $file_show = $fileRename;
     }
     $typefile = $_FILES['fileupload']['type'];
     $sizefile = $_FILES['fileupload']['size'];
     //$tempfile = "file/".date("Y-m-d")."-".$file;
     $url = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $file_show;
     $url_save_in_db = "/docs/files/" . $folder1 . "/" . $folder2 . "/" . $fileRename;
     $structure = str_replace("\\", "/", UPLOAD_PATH . $folder1 . "/" . $folder2);
     //$structure = $_SERVER ['DOCUMENT_ROOT'] . '/file/' . $folderName;
     echo UPLOAD_PATH;
     if (!is_dir($structure)) {
         @mkdir($structure, 0777, true);
     }
     $tempfile_show = $structure . "/" . urlencode($file_show);
     $tempfile = $structure . "/" . $fileRename;
     $errorCode = $_FILES['fileupload']['error'];
     $this->view->errorCode = $errorCode;
     $id = uniqid();
     if ($errorCode === UPLOAD_ERR_OK) {
         try {
             // $newdate =date( 'y-m-d H:i:s' );
             //  $newdatestr = $newdate->format ( 'y-m-d H:i:s' );
             $filedata = array('ID' => $id, 'NAME' => $fileRename, 'TYPE' => $typefile, 'SIZE' => $sizefile, 'PATH' => $tempfile, 'URL' => $url_save_in_db, 'IS_PUBLIC' => 1, 'FILE_REAL_URL' => $real_url_save_in_db, 'FILE_REAL_NAME' => $real_name_in_db, 'folder_id' => $folderid);
             $file = new Sys_Model_File();
             $file->setId($id)->setName($fileRename)->setType($typefile)->setSize($sizefile)->setPath($tempfile)->setUrl($url_save_in_db)->setIsPublic(1)->setIsActive(1)->setFileRealName($real_name_in_db)->setFileRealUrl($real_url_save_in_db)->setFolderId($folderid);
             $this->view->file = $file->save();
         } catch (Exception $e) {
             $error_message = $e->getMessage();
             $this->view->error_message = $error_message;
         }
         move_uploaded_file($_FILES['fileupload']['tmp_name'], $tempfile);
         //copy($_FILES['fileupload']['tmp_name'],$tempfile);
     } else {
         $error_message = $this->file_upload_error_message($errorCode);
         $this->view->errorCode = $arrayErrorCode[$errorCode];
         $this->view->errorCode = errorCode;
     }
 }
Ejemplo n.º 2
0
 function getFileList()
 {
     $file = new Sys_Model_File();
     return $file->fetchAll($file->select()->where("folder_id=?", $this->id)->where("is_active=1"));
 }
Ejemplo n.º 3
0
 /**
  * get Singleton  Sys_Model_File
  *
  * @return Sys_Model_File
  */
 public static function getObjectByID($id)
 {
     $obj = new Sys_Model_File();
     $obj->find($id);
     return $obj;
 }