-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupload.php
54 lines (49 loc) · 1.59 KB
/
upload.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/*
*
* convertFFS.com
*
* Gets file from AJAX file upload system, and returns the file contents or an error code.
*
*/
//Including and then loading the error handling class.
require_once( 'php/errorHandler.php' );
$errorHandler = new ErrorHandler( );
//Checking if it is just someone dicking around on upload.php instead of actually uploading.
if( !count( $_FILES ) )
{
header( "Location: tsk.html" );
die( );
}
//Setting the content type to plain text to prevent some odd HTML rendering engine behaviour.
header( 'Content-type: text/plain' );
//Lets see if the file is bigger than 40mb
if( $_FILES[ 'userfile' ][ 'size' ] > 40000000 )
{
$errorHandler->handle( '~SIZE~' );
}
//Separating the file extension from the file name.
$uploadedFileExtension = pathinfo( $_FILES[ 'userfile' ][ 'name' ] );
$uploadedFileFilename = $uploadedFileExtension[ 'filename' ];
$uploadedFileExtension = $uploadedFileExtension[ 'extension' ];
//Checking if the file extension is supported.
$allowedExtensionArray = array( 'txt', 'pwn', 'pawn', 'map', 'ini', 'cfg', 'xml', 'html', 'htm', 'csv' );
if( !in_array( $uploadedFileExtension, $allowedExtensionArray ) )
{
$errorHandler->handle( '~UNSUPPORTED~' );
}
if( $_FILES[ 'userfile' ][ 'error' ] > 0)
{
$errorHandler->handle( '~ERROR~' );
}
if( empty( $uploadedFileFilename ) )
{
$errorHandler->handle( '~ERROR~' );
}
if( empty( $_FILES[ 'userfile' ][ 'tmp_name' ] ) )
{
$errorHandler->handle( '~ERROR~' );
}
//All checks complete, lets echo the file contents!
echo @file_get_contents( $_FILES[ 'userfile' ][ 'tmp_name' ] );
?>