function create_zip_from_dir_contents($dir, $zipfile_basename) { $zip_archive_path = $dir . '/' . $zipfile_basename . '.zip'; $zipfile = new ZipArchive(); $zipfile->open($zip_archive_path, ZipArchive::CREATE); foreach (scandir($dir) as $f) { $f_path = $dir . '/' . $f; if (file_is_pdf($f_path)) { $zipfile->addFile($f_path, $zipfile_basename . '/' . $f); } } $zipfile->close(); if (file_exists($zip_archive_path)) { return $zip_archive_path; } else { return false; } }
die('You cannot resubmit at this time.'); } $SUBMISSION_DIR = BACKEND_ROOT . '/submissions/'; $the_user = $USERINVENTORY->get_user_by_email_address($_POST['email_address']); $user_uploaded_paper = $the_user->get_uploaded_paper(); if (isset($user_uploaded_paper)) { // keep paper id the same if this a re-upload so we just overwrite the file $new_id = $user_uploaded_paper['id']; } else { // if it's a new upload, generate unique id; should probably be encapsulated elsewhere $used_ids = $USERINVENTORY->get_used_paper_ids(); $new_id = max($used_ids) + 1; } $new_basename = $new_id . '.pdf'; $new_title = $_POST['paper_title']; if (file_is_pdf($_FILES['uploaded_file']['tmp_name'])) { move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $SUBMISSION_DIR . $new_basename); $USERINVENTORY->set_user_uploaded_paper_by_email_address($the_user->get_email_address(), $new_id, $new_title); $USERINVENTORY->write_user_data(); } else { unlink($_FILES['uploaded_file']['tmp_name']); die('File is not a PDF. Only PDFs can be uploaded.'); } ?> <html> <h1>File upload successful!</h1> <p>Your submission "<?php echo $_POST['paper_title']; ?>