コード例 #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
$filename = '20151007110121.pdf';
$converted_file = '20151007110121.txt';
$filename = Utils::manageFileUpload();
if (!$filename) {
    $result = 'C\'è stato un problema durante l\'upload del file';
} else {
    if (strpos($filename, '.pdf') !== false) {
        if (Utils::getValue('template') == 'nestle') {
            $pdfToText = XPDF\PdfToText::create();
            // PDF text is now in the $text variable
            $sheetData = $pdfToText->getText(PROJ_ROOT . '/upload/' . $filename);
            echo $sheetData;
            die;
        } else {
            if (Utils::getValue('template') == 'monge') {
                $pdfToText = XPDF\PdfToText::create(array('-layout'));
                // PDF text is now in the $text variable
                $sheetData = $pdfToText->getText(PROJ_ROOT . '/upload/' . $filename);
                echo $sheetData;
                die;
            }
        }
        //
    }
}
/*
$pdfToText = XPDF\PdfToText::create(array(
    'pdftotext.binaries' => PROJ_ROOT.'/xpdf-3.04/xpdf/',
));*/
/*$options = '';
//read main options and add to request