scratch – Blame information for rev 14

Subversion Repositories:
Rev:
Rev Author Line No. Line
7 office 1 <?php
2  
3 ###########################################################################
4 ## Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 ##
5 ###########################################################################
6  
13 office 7 require_once('inc/pseudocrypt.php');
8 require_once('inc/functions.php');
7 office 9 require_once('config.php');
10  
11 office 11 #### Retrieve uploaded file.
12 if (!empty($_FILES['file']) and
7 office 13 is_uploaded_file($_FILES['file']['tmp_name'])) {
14 # Regular multipart/form-data upload.
15 $name = $_FILES['file']['name'];
16 $data = file_get_contents($_FILES['file']['tmp_name']);
17 } else {
18 # Raw POST data.
19 $name = urldecode(@$_SERVER['HTTP_X_FILE_NAME']);
20 $data = file_get_contents("php://input");
21 }
22  
14 office 23 #### Grab the file extension.
7 office 24 $fileExtension = pathinfo($name, PATHINFO_EXTENSION);
11 office 25  
14 office 26 #### If the extension is not allowed then change it to a text extension.
27 if (!isset($fileExtension) ||
11 office 28 !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS))
14 office 29 $fileExtension = 'txt';
30  
31 #### Hash filename.
11 office 32 $file = strtolower(
33 PseudoCrypt::hash(
34 preg_replace(
35 '/\D/',
36 '',
37 hash(
38 'sha512',
39 $name
7 office 40 )
41 )
14 office 42 ). '.'.
11 office 43 $fileExtension
44 );
14 office 45  
46 #### Build the user path.
11 office 47 $userPath = join(
48 DIRECTORY_SEPARATOR,
49 array(
50 $STORE_FOLDER,
51 $file
52 )
53 );
54  
14 office 55 #### Check for path traversals
11 office 56 $pathPart = pathinfo($userPath);
14 office 57 if (realpath($pathPart['dirname']) != realpath($STORE_FOLDER))
58 return;
7 office 59  
14 office 60 #### Store the file.
61 atomized_put_contents($userPath, $data);
62  
11 office 63 ### Return the URL to the file.
7 office 64 header('Content-Type: text/plain; charset=utf-8');
14 office 65 echo sprintf('%s/%s', trim($URL_PATH, '/'), $file);