Exemple #1
0
 function on_submit()
 {
     $title = Url::get('title');
     $url = Url::get('url');
     $des = Url::get('des');
     if ($des == '<br>') {
         $des = $title;
     }
     $this->checkFormInput("Tên tài liệu", "title", $title, "str", true, '', 1);
     if (!$this->errNum) {
         $uploadPath = AZLib::uploadDocPath();
         //Insert to document
         $doc_id = DB::insert('document', array('title' => addslashes($title), 'des' => addslashes($des), 'status' => 1, 'time_c' => TIME_NOW, 'user_c' => User::user_name(), 'time_m' => TIME_NOW, 'user_m' => User::user_name(), 'file_path' => ''));
         if ($doc_id) {
             if ($url != '') {
                 DB::update('document', array('file_path' => '', 'url' => $url), "id={$doc_id}");
             } elseif (isset($_FILES['file_path']) && $_FILES['file_path']['error'] == 0) {
                 $ext = strtolower(AZLib::getExtension($_FILES['file_path']['name']));
                 $file_name = AZLib::safe_title(basename(strtolower($_FILES['file_path']['name']), $ext)) . $ext;
                 $up_file = $uploadPath . date('Y.m.d_H\\hi.s') . "-{$doc_id}-{$file_name}";
                 $file_path = str_replace(DATA_PATH . "document/", '', $up_file);
                 chmod($uploadPath, 0777);
                 if (!move_uploaded_file($_FILES['file_path']['tmp_name'], $up_file)) {
                     DB::delete('document', "id={$doc_id}");
                     $this->setFormError('file_path', "Không upload được file!");
                     return;
                 } else {
                     DB::update('document', array('file_path' => $file_path), "id={$doc_id}");
                 }
             }
             Url::redirect_current();
             //Url::redirect_current(array('cmd'=>'add'));
         } else {
             $this->setFormError('name', "Không thêm được tài liệu, hãy thử lại sau!");
         }
     }
 }