Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- ob_start();
- require_once('header.php');
- if (!isset($_SESSION['project'])) {
- header("Location: index.php");
- }
- function ajaxErrorDetect($error_message) {
- if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
- ob_clean();
- header('HTTP/1.1 500 Internal Server Error');
- header('Content-type: text/plain');
- exit($error_message);
- }
- else {
- }
- }
- function createDirectory($dirPath) {
- $error_check = true;
- for ($i=0; $i <= 2; $i++) {
- if ($error_check == true) {
- if (!file_exists($dirPath[$i])) {
- mkdir($dirPath[$i], 0777, true);
- }
- else {
- }
- }
- }
- return $error_check;
- }
- //Change this to only delete the directory the failed file is trying to upload to!!!
- function deleteDirectory($targetPath) {
- if (is_dir($targetPath)) {
- $objects = scandir($targetPath);
- foreach ($objects as $object) {
- if ($object != "." && $object !="..") {
- if (filetype($targetPath . DIRECTORY_SEPARATOR . $object) == "dir") {
- deleteDirectory($targetPath . DIRECTORY_SEPARATOR . $object);
- } else {
- unlink($targetPath . DIRECTORY_SEPARATOR . $object);
- }
- }
- }
- reset($objects);
- rmdir($targetPath);
- }
- }
- $ds = DIRECTORY_SEPARATOR;
- $storeFolder = 'uploads';
- $error_message = '';
- //Check if delete passed in header
- if (isset($_GET['delete_pg'])) { //---------------------------------------------------------------------------------UPDATE FOR THIS SHOULD BE DONE VIA JQUERY!!!!
- $page = mysqli_real_escape_string($db, $_GET['delete_pg']);
- //Delete associated files
- if (file_exists(__DIR__ . "/submissions/2017/{$_SESSION['project']}/pdf/{$_SESSION['project']}_page_". $page .".pdf")) {
- unlink(__DIR__ . "/submissions/2017/{$_SESSION['project']}/pdf/{$_SESSION['project']}_page_". $page .".pdf");
- }
- if (file_exists(__DIR__ . "/submissions/2017/{$_SESSION['project']}/jpeg/{$_SESSION['project']}_page_". $page .".jpeg")) {
- unlink(__DIR__ . "/submissions/2017/{$_SESSION['project']}/jpeg/{$_SESSION['project']}_page_". $page .".jpeg");
- }
- if (file_exists(__DIR__ . "/submissions/2017/{$_SESSION['project']}/thumbnails/{$_SESSION['project']}_page_". $page ."_thumbnail.jpeg")) {
- unlink(__DIR__ . "/submissions/2017/{$_SESSION['project']}/thumbnails/{$_SESSION['project']}_page_". $page ."_thumbnail.jpeg");
- }
- //Prepare sql query
- $sql = "
- UPDATE `submissions`
- SET `proposal_pg". $page ."` = NULL
- WHERE `project` = '{$_SESSION['project']}'
- ";
- $db->query($sql);
- header("Location: submit.php"); //---------------------------------------------------------NO, UPDATE THROUGH JQUERY!
- }
- //If filesize overwhelms php.ini
- if ($_SERVER['REQUEST_METHOD'] == 'POST' && empty($_POST) && empty($_FILES) && $_SERVER['CONTENT_LENGTH'] > 0 ) {
- $error_message = 'Error: File size can not exceed 7mb';
- ajaxErrorDetect($error_message);
- }
- //If php detects there are filed being transmitted
- if (!empty($_FILES)) {
- $project = $_SESSION['project'];
- //UPDATE DB ENTRY
- /* while ($row = $result->fetch_assoc()) {
- $id = $row['id'];
- } */
- //Initialize variable scope
- $fileNo = '';
- //Check which file has been uploaded
- if (isset($_FILES['file_01']['name'])) {
- $fileNo = '1';
- }
- else if (isset($_FILES['file_02']['name'])) {
- $fileNo = '2';
- }
- else if (isset($_FILES['file_03']['name'])) {
- $fileNo = '3';
- }
- //Bind the files to the appropriate variables
- $fileBase= basename(strtolower($_FILES['file_0'. $fileNo]['name']));
- $fileSize = $_FILES['file_0' . $fileNo]['size'];
- $fileType = $_FILES['file_0' . $fileNo]['type'];
- $tempFile = $_FILES['file_0' . $fileNo]['tmp_name'];
- //Confirm that the file sent over is under 7mb (1024 conversion)
- if ($fileSize >= 7340032) {
- $error_message = 'Error: File size can not exceed 7mb';
- ajaxErrorDetect($error_message);
- }
- else {
- if ($fileType != 'application/pdf') {
- $error_message = 'Error: You may only upload files in PDF form';
- ajaxErrorDetect($error_message);
- }
- else {
- //Prepare variables with the appropriate path names
- $targetPath = 'submissions/2017/' . $project;
- $newFileName = $project . '_page_' . $fileNo;
- $targetFile = $targetPath . '/pdf/' . $newFileName . '.pdf';
- //Prepare an array that will store the appropriate paths to the different image and pdf folders
- $dirPath = array();
- array_push($dirPath, $targetPath . '/pdf', $targetPath . '/jpeg', $targetPath . '/thumbnails');
- //If the directory was successfully created
- if (!createDirectory($dirPath)) {
- $error_message = 'Error: Could not create directory. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- else {
- //Upload the transferred files
- if (!move_uploaded_file($tempFile, $targetFile)) {
- $error_message = 'Error: Could not transfer files. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- else {
- //Prepare variables with the appropriate path names
- $pdfPath = __DIR__ . $ds . $targetFile;
- $jpgPath = __DIR__ . $ds . $targetPath . '/jpeg/' . $newFileName . '.jpeg';
- $thumbPath = __DIR__ . $ds . $targetPath . '/thumbnails/' . $newFileName . '_thumbnail.jpeg';
- //Get page count
- $pagecount = exec('identify -format %n '. $pdfPath);
- //If page 1 or 2 do not have more than 1 page then:
- if ($pagecount == 1 || $fileNo == '3') {
- //Create JPG from PDF
- exec('convert -density 300 ' . $pdfPath . '[0] ' . $jpgPath);
- //Get page dimensions from newly created JPG
- $size = getimagesize($jpgPath);
- $width = $size[0];
- $height = $size[1];
- //Determine the orientation of the submitted files
- if ($fileNo == 1 || $fileNo == 2) {
- if ($height > $width) {
- $orientation = 'portrait';
- //Rotate and produce thumbnail from pdf
- exec('convert -colorspace sRGB -rotate 90 -resize 306x198 -background white -extent 306x198 -quality 100 ' . $pdfPath . '[0] ' . $thumbPath);
- //Reduce the size of the produced full jpeg
- exec('convert -colorspace sRGB -resize 792x1224 -background white -extent 792x1224 -quality 100 ' . $jpgPath . ' ' . $jpgPath);
- }
- else {
- $orientation = 'landscape';
- //Produce landscape thumbnail from pdf
- exec('convert -colorspace sRGB -resize 306x198 -background white -extent 306x198 -quality 100 ' . $pdfPath . '[0] ' . $thumbPath);
- //Reduce the size of the produced full jpeg
- exec('convert -colorspace sRGB -resize 1224x792 -background white -extent 1224x792 -quality 100 ' . $jpgPath . ' ' . $jpgPath);
- }
- }
- else if ($fileNo == 3) {
- if ($height > $width) {
- $orientation = 'portrait';
- //Produce portrait thumbnail from pdf
- exec('convert -colorspace sRGB -resize 155x198 -background white -extent 155x198 -quality 100 ' . $pdfPath . '[0] ' . $thumbPath);
- //Reduce the size of the produced full jpeg
- exec('convert -colorspace sRGB -resize 613x792 -background white -extent 613x792 -quality 100 ' . $jpgPath . ' ' . $jpgPath);
- }
- else {
- $orientation = 'landscape';
- //Rotate and produce thumbnail from pdf
- exec('convert -colorspace sRGB -rotate 90 -resize 155x198 -background white -extent 155x198 -quality 100 ' . $pdfPath . '[0] ' . $thumbPath);
- //Reduce the size of the produced full jpeg
- exec('convert -colorspace sRGB -resize 792x613 -background white -extent 792x613 -quality 100 ' . $jpgPath . ' ' . $jpgPath);
- }
- }
- else {
- $error_message = 'Error: Unknown file. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- //Prepare the database query to get the ID of the proper project to update with the newly-uploaded files
- $sql = "SELECT * FROM `submissions` WHERE `project` = '$project'";
- $result = $db->query($sql);
- if ($result->num_rows() == 0) {
- //CREATE DB ENTRY
- $sql = "
- INSERT INTO `submissions` (
- `project`,
- `proposal_pg". $fileNo ."`)
- VALUES (
- ?,
- ?,
- )";
- $statement = $db->prepare($sql);
- $statement->bind_param('ss', $project, $newFileName);
- $statement->execute();
- $statement->close();
- }
- else {
- //Prepare query for new file link
- $sql = "
- UPDATE `submissions`
- SET `proposal_pg". $fileNo ."` = '$newFileName'
- WHERE `project` = '$project'
- ";
- $db->query($sql);
- }
- //Prompt saying the files were successfully uploaded
- $error_message = 'File successfully uploaded';
- ajaxErrorDetect($error_message);
- }
- else {
- if (isset($targetFile)) {
- if (file_exists($pdfPath)) {
- unlink($pdfPath);
- }
- if (file_exists($jpgPath)) {
- unlink($jpgPath);
- }
- if (file_exists($thumbPath)) {
- unlink($thumbPath);
- }
- $sql = "
- UPDATE `submissions`
- SET `proposal_pg". $fileNo ."` = NULL
- WHERE `project` = '$project'
- ";
- $db->query($sql);
- $error_message = 'Error: Pages 1 and 2 cannot contain multi-page pdfs.';
- ajaxErrorDetect($error_message);
- }
- }
- }
- }
- }
- }
- }
- ?>
- <div id="panel" class="submit-panel">
- <script>
- var errorMessage = <?php print json_encode($error_message); ?>,
- project = <?php print json_encode($_SESSION['project']); ?>;
- </script>
- <h2>Submit</h2>
- <?php if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {?>
- <span class="close-panel">X</span>
- <?php } ?>
- <div class="error-rep"></div>
- <div class="form-divider"></div>
- <div class="form-subheader">PAGE ONE</div>
- <div class="upload-container ledger" id="file_01">
- <div class="ledger-preview" <?php
- //Default page set status to false
- $page_one_set = false;
- //Prepare the query
- $sql = "
- SELECT *
- FROM `submissions`
- WHERE `project` = '{$_SESSION['project']}'
- ";
- if (!$result = $db->query($sql)) {
- die();
- $error_message = 'Error: There was an error running the query. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- while($row = $result->fetch_assoc()) {
- if ($row['proposal_pg1'] != NULL) {
- $page_one_set = true;
- print 'style="background-image: url(\'submissions/2017/'. $_SESSION['project'] . '/thumbnails/' . $row['proposal_pg1'] . '_thumbnail.jpeg?' . time() . '\')"';
- }
- }
- ?>>
- <form class="dropzone" id="file-one" action="submit.php" method="post" enctype="multipart/form-data">
- <div class="progress-container">
- <div class="progress-bar">
- <div class="progress-fill">
- </div>
- </div>
- <div class="progress-text">
- </div>
- </div>
- <span class="preview-add">
- <?php
- if ($page_one_set == false) {
- print "+";
- }
- ?>
- </span>
- <div class="file-upload-offset">
- <div class="preview-options"><?php
- if ($page_one_set == true) {
- ?>
- <span class="submission-view"><a href="<?php print "submissions/2017/{$_SESSION['project']}/pdf/{$_SESSION['project']}_page_1.pdf"; ?>">View</a></span> | <span class="submission_remove"><a href="<?php print "submit.php?delete_pg=1"; ?>">Delete</a></span>
- <?php } ?>
- </div>
- <div class="fallback">
- <input name="file_01" type="file" accept="application/pdf" /><br /><br />
- <input type="submit" value="Upload" />
- </div>
- </div>
- </form>
- </div>
- </div>
- <div class="preview-description">
- <span>Requirements Checklist:</span>
- <ul class="submissions-checklist">
- <div>□ 11 x 17" (279mm x 432mm).</div>
- <div>□ Single-page PDF file under 7mb.</div>
- <div>□ A maximum of 150 word text describing the project and presenting the
- experience offered by the visitors.</div>
- <div>□ Layout of selected images and drawings describing the project.</div>
- </ul>
- </div>
- <div class="form-divider"></div>
- <div class="form-subheader">PAGE TWO</div>
- <div class="upload-container ledger" id="file_02">
- <div class="ledger-preview" <?php
- //Default page set status to false
- $page_two_set = false;
- //Prepare the query
- $sql = "
- SELECT *
- FROM `submissions`
- WHERE `project` = '{$_SESSION['project']}'
- ";
- if (!$result = $db->query($sql)) {
- die();
- $error_message = 'Error: There was an error running the query. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- while($row = $result->fetch_assoc()) {
- if ($row['proposal_pg2'] != NULL) {
- $page_two_set = true;
- print 'style="background-image: url(\'submissions/2017/'. $_SESSION['project'] . '/thumbnails/' . $row['proposal_pg2'] . '_thumbnail.jpeg?' . time() . '\')"';
- }
- }
- ?>>
- <form class="dropzone" id="file-two" action="submit.php" method="post" enctype="multipart/form-data">
- <div class="progress-container">
- <div class="progress-bar">
- <div class="progress-fill">
- </div>
- </div>
- <div class="progress-text">
- </div>
- </div>
- <span class="preview-add">
- <?php
- if ($page_two_set == false) {
- print "+";
- }
- ?>
- </span>
- <div class="file-upload-offset">
- <div class="preview-options"><?php
- if ($page_two_set == true) {
- ?>
- <span class="submission-view"><a href="<?php print "submissions/2017/{$_SESSION['project']}/pdf/{$_SESSION['project']}_page_2.pdf"; ?>">View</a></span> | <span class="submission_remove"><a href="<?php print "submit.php?delete_pg=2"; ?>">Delete</a></span>
- <?php } ?>
- </div>
- <div class="fallback">
- <input name="file_02" type="file" accept="application/pdf" /><br /><br />
- <input type="submit" value="Upload" />
- </div>
- </div>
- </form>
- </div>
- </div>
- <div class="preview-description">
- <span>Requirements Checklist:</span>
- <ul class="submissions-checklist">
- <div>□ 11 x 17" (279mm x 432mm).</div>
- <div>□ Single-page PDF file under 7mb.</div>
- <div>□ 4 main views or elevations of the installation indicating
- size and specification of materials. Entrant is free to
- choose the scale.</div>
- <div>□ A perspective showing the design in its entirety.</div>
- </ul>
- </div>
- <div class="form-divider"></div>
- <div class="form-subheader">PAGE THREE</div>
- <div class="upload-container ledger" id="file_03">
- <div class="letter-preview" <?php
- //Default page set status to false
- $page_three_set = false;
- //Prepare the query
- $sql = "
- SELECT *
- FROM `submissions`
- WHERE `project` = '{$_SESSION['project']}'
- ";
- if (!$result = $db->query($sql)) {
- die();
- $error_message = 'Error: There was an error running the query. Please report this error to info@winterstations.com';
- ajaxErrorDetect($error_message);
- }
- while($row = $result->fetch_assoc()) {
- if ($row['proposal_pg3'] != NULL) {
- $page_three_set = true;
- print 'style="background-image: url(\'submissions/2017/'. $_SESSION['project'] . '/thumbnails/' . $row['proposal_pg3'] . '_thumbnail.jpeg?' . time() . '\')"';
- }
- }
- ?>>
- <form class="dropzone" id="file-three" action="submit.php" method="post" enctype="multipart/form-data">
- <div class="progress-container">
- <div class="progress-bar">
- <div class="progress-fill">
- </div>
- </div>
- <div class="progress-text">
- </div>
- </div>
- <span class="preview-add">
- <?php
- if ($page_three_set == false) {
- print "+";
- }
- ?>
- </span>
- <div class="file-upload-offset">
- <div class="preview-options"><?php
- if ($page_three_set == true) {
- ?>
- <span class="submission-view"><a href="<?php print "submissions/2017/{$_SESSION['project']}/pdf/{$_SESSION['project']}_page_3.pdf"; ?>">View</a></span> | <span class="submission_remove"><a href="<?php print "submit.php?delete_pg=3"; ?>">Delete</a></span>
- <?php } ?>
- </div>
- <div class="fallback">
- <input name="file_03" type="file" accept="application/pdf" /><br /><br />
- <input type="submit" value="Upload" />
- </div>
- </div>
- </form>
- </div>
- </div>
- <div class="preview-description">
- <span>Requirements Checklist:</span>
- <ul class="submissions-checklist">
- <div>□ 8.5 x 11" (216mm x 279mm)</div>
- <div>□ PDF file under 7mb</div>
- <div>□ Design team member names, with brief CV for each.</div>
- <div>□ A 100 word description of the team, highlighting its strength.</div>
- <div>□ Name, location and date of recent publications, projects, or exhibitions.</div>
- <div>□ Images of selected projects for which team members have been responsible, followed with a brief description.</div>
- </ul>
- </div>
- <div class="form-divider"></div>
- <div>Click or drag and drop your files into the dashed boxes above. Please allow a few minutes for processing.
- If you see your submission in the thumbnails above (click 'View' if you are unsure), this means we have received your entry.
- You may edit your submissions here until November 4, 2016.
- Should you experience any difficulty uploading your files, please contact <a class="email-link-tomek"></a></div>
- </div>
- </ul>
- <?php include_once('footer.php'); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement