<?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));
<?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"); // Change the filename (in this case, we are using a variable called $id to ensure the file has a unique name) $time = time(); $suid = $_POST['suid']; $file->set_filename("{$suid}.pdf"); $suid_time = $suid . $time; // 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) { copy("/afs/ir/users/a/l/alexoz/uploads/{$suid}.pdf", "/afs/ir/users/a/l/alexoz/uploads/{$suid_time}.pdf"); ob_start(); // Display a success message echo "<p>File upload complete!</p>\n"; header("LOCATION: http://www.stanford.edu/~alexoz/cgi-bin/file_upload_form.html"); // Don't display the form $display_form = false;