scratch – Blame information for rev 13

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  
23 $fileExtension = pathinfo($name, PATHINFO_EXTENSION);
11 office 24  
25 #### Check that the file extension is allowed.
26 if(!isset($fileExtension) ||
27 !in_array(strtoupper($fileExtension), $ALLOWED_FILE_EXTENSIONS))
28 return;
29  
30 #### Hash filename and check storage in the upload folder.
31 $storePath = realpath($STORE_FOLDER);
32 $file = strtolower(
33 PseudoCrypt::hash(
34 preg_replace(
35 '/\D/',
36 '',
37 hash(
38 'sha512',
39 $name
7 office 40 )
41 )
11 office 42 ).
43 '.'.
44 $fileExtension
45 );
46 $userPath = join(
47 DIRECTORY_SEPARATOR,
48 array(
49 $STORE_FOLDER,
50 $file
51 )
52 );
53  
54 #### Check for path traversals.
55 $pathPart = pathinfo($userPath);
56 if (realpath($pathPart['dirname']) == $storePath) {
57 atomized_put_contents($userPath, $data);
58 $output = sprintf('%s/%s', trim($URL_PATH, '/'), $file);
7 office 59 }
60  
11 office 61 ### Return the URL to the file.
7 office 62 header('Content-Type: text/plain; charset=utf-8');
63 echo $output;