function uploadFiles($uid, $pid, $type, $file) { if (!canViewPuzzle($uid, $pid)) { utilsError("You do not have permission to modify this puzzle."); } if ($type == 'draft' && !canAcceptDrafts($pid)) { utilsError("This puzzle has been finalized. No new drafts can be uploaded."); } $extension = ""; $target_path = "uploads/puzzle_files/" . uniqid(); $filename_parts = explode(".", $file['name']); if (count($filename_parts) > 1) { $target_path = $target_path . "." . end($filename_parts); $extension = end($filename_parts); } if (USING_AWS) { $client = S3Client::factory(array('key' => AWS_ACCESS_KEY, 'secret' => AWS_SECRET_KEY)); } if ($extension == "zip") { $filetype = "dir"; if (move_uploaded_file($file['tmp_name'], $target_path)) { if (USING_AWS) { $key = $target_path; $result = $client->putObject(array('Bucket' => AWS_BUCKET, 'Key' => $key, 'Body' => file_get_contents($target_path), 'ContentDisposition' => 'inline')); } $new_path = $target_path . "_" . $filetype; #echo "target_path is $target_path<br>"; #echo "new_path is $new_path<br>"; $res = exec("/usr/bin/unzip {$target_path} -d {$new_path}"); if (USING_AWS) { $result = $client->uploadDirectory($new_path, AWS_BUCKET, $new_path); } $sql = sprintf("INSERT INTO uploaded_files (filename, pid, uid, cid, type) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($new_path), mysql_real_escape_string($pid), mysql_real_escape_string($uid), mysql_real_escape_string(-1), mysql_real_escape_string($type)); query_db($sql); $sql = sprintf("INSERT INTO uploaded_files (filename, pid, uid, cid, type) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($target_path), mysql_real_escape_string($pid), mysql_real_escape_string($uid), mysql_real_escape_string(-1), mysql_real_escape_string($type)); query_db($sql); if (USING_AWS) { addComment($uid, $pid, "A new <a href=\"https://" . AWS_BUCKET . ".s3.amazonaws.com/list.html?prefix={$new_path}\">{$type}</a> has been uploaded.", TRUE); } else { addComment($uid, $pid, "A new <a href=\"{$new_path}\">{$type}</a> has been uploaded.", TRUE); } } else { $_SESSION['upload_error'] = "There was an error uploading the file, please try again. (Note: file max size may be limited)"; } } else { $upload_error = ""; if (move_uploaded_file($file['tmp_name'], $target_path)) { if (USING_AWS) { $key = $target_path; $result = $client->putObject(array('Bucket' => AWS_BUCKET, 'Key' => $key, 'Body' => file_get_contents($target_path), 'ContentDisposition' => 'inline')); } $sql = sprintf("INSERT INTO uploaded_files (filename, pid, uid, cid, type) VALUES ('%s', '%s', '%s', '%s', '%s')", mysql_real_escape_string($target_path), mysql_real_escape_string($pid), mysql_real_escape_string($uid), mysql_real_escape_string(-1), mysql_real_escape_string($type)); query_db($sql); if (USING_AWS) { addComment($uid, $pid, "A new <a href=\"https://" . AWS_BUCKET . ".s3.amazonaws.com/{$target_path}\">{$type}</a> has been uploaded.", TRUE); } else { addComment($uid, $pid, "A new <a href=\"{$target_path}\">{$type}</a> has been uploaded.", TRUE); } } else { $_SESSION['upload_error'] = "There was an error uploading the file, please try again. (Note: file max size may be limited) " . serialize($file); } } if ($type == "postprod") { // pushToPostProd($uid, $pid); } }
function displayFileList($uid, $pid, $type) { $fileList = getFileListForPuzzle($pid, $type); $first = TRUE; if (!$fileList) { $file['filename'] = '(none)'; $file['date'] = NULL; $fileList[] = $file; } foreach ($fileList as $file) { $finfo = pathinfo($file['filename']); $filename = $finfo['basename']; if (strpos($file['filename'], 'http') !== false || !USING_AWS) { $link = $file['filename']; } else { if (strpos($file['filename'], '_dir', strlen($file['filename']) - 4) !== false) { $link = 'https://' . AWS_BUCKET . '.s3.amazonaws.com/list.html?prefix=' . $file['filename']; } else { $link = 'https://' . AWS_BUCKET . '.s3.amazonaws.com/' . $file['filename']; } } $date = $file['date']; if ($first) { $class = 'fileInfoLatest'; ?> <tr> <td class='<?php echo $class; ?> '> <?php echo "<strong>Latest {$type}:</strong>"; ?> </td> <?php } else { $class = 'fileInfoOld'; ?> <tr> <td class='<?php echo $class; ?> '> <?php echo "Older {$type}:"; ?> </td> <?php } ?> <?php if ($file['filename'] == '(none)') { ?> <td class='<?php echo $class; ?> ' colspan='2'> (none) </td> <?php } else { ?> <td class='<?php echo $class; ?> '> <?php echo "<a href='{$link}'/>{$filename}</a>"; ?> </td> <td class='<?php echo $class; ?> '> <?php echo "{$date}"; ?> </td> <?php } if ($first && !($type == 'draft' && !canAcceptDrafts($pid))) { ?> <td class='<?php echo $class; ?> '> <a href="#" id="<?php echo "upload{$type}" . "Link"; ?> ">[Upload New]</a> </td> </tr> <tr id='<?php echo "upload{$type}"; ?> '> <form enctype="multipart/form-data" method="post" action="form-submit.php"> <input type="hidden" name="pid" value="<?php echo $pid; ?> " /> <input type="hidden" name="filetype" value="<?php echo $type; ?> " /> <input type="hidden" name="uid" value="<?php echo $uid; ?> " /> <td class='<?php echo $class; ?> ' colspan='3'> <input type="file" name="fileupload" /> <input type="submit" name="uploadFile" value="Upload" /> </td> </form> </tr> <?php if (isset($_SESSION['upload_error'])) { echo '<span class="error">' . $_SESSION['upload_error'] . '</span>'; unset($_SESSION['upload_error']); } } else { ?> </tr> <?php } if ($first) { $first = FALSE; } } }