Append original (but secured) file name to random file name (optional).
[simple-upload.git] / README.md
1 # Simple PHP upload
2
3 Simple single-file PHP file upload (file share hosting) script.
4
5 > :warning: **Security warning**: There is no limit on file size or file type. Please make sure that file permissions are set right so nobody can execute uploaded code. See [server configuration](#server-configuration) for examples.
6
7 ## TODO
8
9 - [x] Delete files
10 - [x] Private files
11 - [x] Sort by age
12 - [x] Auto-remove old files
13 - [ ] AJAX Uploader
14
15 ## Installation
16
17 Just drop a PHP file in any directory. It will work straight away
18
19 ## Configuration
20
21 There are few options that you can change by editing the file itself:
22
23
24 - Directory to store uploaded files
25
26         `uploaddir` => `'.'`
27
28 - Display list uploaded files
29
30         `listfiles` => `true`
31
32 - Allow users to delete files that they have uploaded (will enable sessions)
33
34         `allow_deletion` => `true`
35
36 - Display file sizes
37
38         `listfiles_size` => `true`
39
40 - Display file dates
41
42         `listfiles_date` => `true`
43
44 - Display file dates format
45
46         `listfiles_date_format` => `'F d Y H:i:s'`
47
48 - Randomize file names (number of 'false')
49
50         `random_name_len` => `4`
51
52 - Keep filetype information (if random name is activated)
53
54         `random_name_keep_type` => `true`
55
56 - Random file name letters
57
58         `random_name_alphabet` => `'qwertyuiopasdfghjklzxcvbnm'`
59
60 - Display debugging information
61
62         `debug` => `($_SERVER['SERVER_NAME'] === 'localhost')`
63
64 ## Usage options
65
66 - Through an interface:
67         - Choose files via dialogue
68         - Drop files, via HTML5 drag'and'drop (using [dropzone.js](http://www.dropzonejs.com/))
69         - Basic HTML Form (if no JavaScript is suported)
70 - Upload using any compatible tool (like cURL)
71
72         This example will upload a file and copy URL to clipboard:
73
74         ```bash
75         curl -F "file[]=@file.jpg" strace.club | xclip -sel clip
76         ```
77
78 ## Server configuration
79
80 Do not allow uploaded code execution!
81
82 ### NGINX configuration example
83
84 Edit the NGINX configuration file (`/etc/nginx/sites-enabled/fileuploader`):
85
86         server {
87                 listen 80 default_server;
88                 listen [::]:80 default_server ipv6only=on;
89
90                 root /usr/share/nginx;
91                 index index.php;
92
93                 server_name localhost;
94
95                 location / {
96                         try_files $uri $uri/ =404;
97                 }
98
99                 error_page 404 /index.php;
100
101                 location /index.php {
102                         fastcgi_split_path_info ^(.+\.php)(/.+)$;
103                         fastcgi_pass unix:/var/run/php5-fpm.sock;
104                         fastcgi_index index.php;
105                         include fastcgi_params;
106                 }
107         }