コード例 #1
0
ファイル: upload.php プロジェクト: harryge00/cs193c
<?php

// Include the class
include_once "stanford.fileupload.php";
// Create a new StanfordFileUpload using the name of the form field associated with the file
$file = new StanfordFileUpload("file");
// Set the max filesize (in KB) and allowed extensions
$file->set_max_filesize(1024);
// 1 MB
$file->set_allowed_extensions("pdf");
// Change the filename (in this case, we are using a the time)
$timestamp = date('ymd_H-i-s');
$file->set_filename("{$timestamp}.pdf");
// Default setting is to display the form
$display_form = true;
// If the file has been uploaded
if ($file->has_been_uploaded() == true) {
    // Set the save directory (directory must exist)
    $file->set_save_directory("/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed");
    // Try to save the file
    if ($file->save() == true) {
        system("python /afs/ir/users/a/l/alexoz/cgi-bin/python/pdfminer/pdf2txt.py -o /afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/{$timestamp}.txt /afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/{$timestamp}.pdf");
        //$pdf_text = str_replace("\n", " ", file_get_contents("/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/$timestamp.txt"));
        $pdf_text = file_get_contents("/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/{$timestamp}.txt");
        $student_name_array = explode("Academic", $pdf_text);
        $student_name = str_replace(" ", "_", strtolower($student_name_array[0]));
        $timestamp_student_name = $timestamp . "_" . $student_name;
        //copy pdf and txt files such that they include the student's name.
        copy("/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/{$timestamp}.pdf", "/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/named/{$timestamp_student_name}.pdf");
        copy("/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/unnamed/{$timestamp}.txt", "/afs/ir/users/a/l/alexoz/uploads/advising/four_year_plans/named/{$timestamp_student_name}.txt");
        print json_encode(array("pdf_text" => $pdf_text));
コード例 #2
0
ファイル: file_upload.php プロジェクト: harryge00/cs193c
<?php

$text = 'HEADING';
// Include the class
include_once "stanford.fileupload.php";
// Create a new StanfordFileUpload using the name of the form field associated with the file
$file = new StanfordFileUpload("my_file");
// Set the max filesize (in KB) and allowed extensions
$file->set_max_filesize(1024);
// 1 MB
$file->set_allowed_extensions("pdf");
// Default setting is to display the form
$display_form = true;
// If the file has been uploaded
if ($file->has_been_uploaded() == true) {
    // Set the save directory (directory must exist)
    $file->set_save_directory(dirname(__FILE__) . "/../uploads/");
    // Try to save the file
    if ($file->save() == true) {
        // Display a success message
        echo "<p>File upload complete!</p>\n";
        exec('python pdfminer/pdf2text.py planner.pdf', $output, $ret_code);
        $x = array(3, 2, 4, 5);
        foreach ($x as $element) {
            echo $element . '<br />';
        }
        // Don't display the form
        $display_form = false;
    } else {
        // Display the list of errors
        $file->display_errors();