コード例 #1
0
ファイル: PDFtoCSVPage.php プロジェクト: phpsmith/IS4C
 public function post_file_handler()
 {
     if (!isset($_FILES['file-upload'])) {
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'No file uploaded!');");
         $this->__route_stem = 'get';
         return true;
     }
     if ($_FILES['file-upload']['error'] != UPLOAD_ERR_OK) {
         $msg = \COREPOS\Fannie\API\lib\UploadLib::errorToMessage($_FILES['file-upload']['error']);
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', '{$msg}');");
         $this->__route_stem = 'get';
         return true;
     }
     $path_parts = pathinfo($_FILES['file-upload']['name']);
     if (!isset($path_parts['extension']) || strtolower($path_parts['extension']) != 'pdf') {
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'Uploaded file is not a .pdf');");
         $this->__route_stem = 'get';
         return true;
     }
     try {
         $obj = XPDF\PdfToText::create();
         $obj->setOutputMode('layout');
         $this->file_content = $obj->getText($_FILES['file-upload']['tmp_name']);
     } catch (Exception $e) {
         $msg = str_replace("'", '', $e->getMessage());
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', '{$msg}');");
         $this->__route_stem = 'get';
     }
     unlink($_FILES['file-upload']['tmp_name']);
     return true;
 }
コード例 #2
0
ファイル: CpwInvoiceImport.php プロジェクト: phpsmith/IS4C
 public function post_file_handler()
 {
     if (!isset($_FILES['file-upload'])) {
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'No file uploaded!');");
         $this->__route_stem = 'get';
         return true;
     }
     if ($_FILES['file-upload']['error'] != UPLOAD_ERR_OK) {
         $msg = \COREPOS\Fannie\API\lib\UploadLib::errorToMessage($_FILES['file-upload']['error']);
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', '{$msg}');");
         $this->__route_stem = 'get';
         return true;
     }
     $path_parts = pathinfo($_FILES['file-upload']['name']);
     if (!isset($path_parts['extension']) || strtolower($path_parts['extension']) != 'xls' && strtolower($path_parts['extension'] != 'csv')) {
         $this->add_onload_command("showBootstrapAlert('#alert-area', 'danger', 'Uploaded file is not a .csv or .xls');");
         $this->__route_stem = 'get';
         return true;
     }
     $name_with_extension = tempnam(sys_get_temp_dir(), 'cpw') . '.' . $path_parts['extension'];
     $tmpfile = $_FILES['file-upload']['tmp_name'];
     move_uploaded_file($tmpfile, $name_with_extension);
     $this->filedata = \COREPOS\Fannie\API\data\FileData::fileToArray($name_with_extension);
     unlink($name_with_extension);
     return true;
 }