Access your file here:\n%s", $url,$url); } else { printf($url); } } else { //TODO: proper error handling printf("An error occurred while uploading file."); } } //////////////////////////////////////////////////////////////////////////////// // purge all files older than their retention period allows. //////////////////////////////////////////////////////////////////////////////// function purgeFiles() { global $STORE_PATH; global $MAX_FILEAGE; global $MAX_FILESIZE; global $MIN_FILEAGE; global $DECAY_EXP; $numDel = 0; //number of deleted files $totalSize = 0; //total size of deleted files //for each stored file foreach (scandir($STORE_PATH) as $file) { //skip virtual . and .. files if ($file == '.' || $file == '..') { continue; } $file = $STORE_PATH . $file; $fileSize = filesize($file) / (1000*1000); //size in MB $fileAge = (time()-filemtime($file)) / (60*60*24); //age in days //keep all files below the min age if ($fileAge < $MIN_FILEAGE) { continue; } //calculate the maximum age, in days, for this file //minage + (maxage-minage) * (1-(size/maxsize))^exp; $fileMaxAge = $MIN_FILEAGE + ($MAX_FILEAGE - $MIN_FILEAGE) * pow(1-($fileSize/$MAX_FILESIZE),$DECAY_EXP); //delete if older if ($fileAge > $MIN_FILEAGE) { unlink($file); printf("deleted \"%s\", %d MB, %d days old\n", $file, $fileSize, $fileAge); $numDel += 1; $totalSize += $fileSize; } } printf("Purge finished. Deleted %d files totalling %d MB\n", $numDel, $totalSize); } //////////////////////////////////////////////////////////////////////////////// // print a plaintext info page, explaining what this script does and how to // use it, how to upload, etc. // essentially the homepage //////////////////////////////////////////////////////////////////////////////// function printInfo() { global $ADMIN_EMAIL; global $HTTP_PROTO; global $MAX_FILEAGE; global $MAX_FILESIZE; global $MIN_FILEAGE; global $DECAY_EXP; $url = $HTTP_PROTO."://".$_SERVER["HTTP_HOST"].$_SERVER['REQUEST_URI']; echo << === How To Upload === You can upload files to this site via a simple HTTP POST, e.g. using curl: curl -F "file=@/path/to/your/file.jpg" $url On Android, you can use an app called Hupl. Or simply choose a file and click "Upload" below:
(Hint: If you're lucky, your browser may support drag-and-drop onto the file 
selection input.)


 === File Sizes etc. ===
The maximum allowed file size is $MAX_FILESIZE MB.

Files are kept for a minimum of $MIN_FILEAGE, and a maximum of $MAX_FILEAGE Days.

How long a file is kept, depends on its size. Larger files are deleted earlier 
than small ones. This relation is non-linear and skewed in favour of small 
files.

The exact formula for determining the maximum age for a file is:

MIN_AGE + (MAX_AGE - MIN_AGE) * (1-(FILE_SIZE/MAX_SIZE))^$DECAY_EXP


 === Source ===
The PHP script used to provide this service is open source and available on 
GitHub


 === Contact ===
If you want to report abuse of this service, or have any other inquiries, 
please write an email to $ADMIN_EMAIL
EOT; } ?>