Skip to content

Instantly share code, notes, and snippets.

@hraban
Created February 12, 2014 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hraban/8957078 to your computer and use it in GitHub Desktop.
Save hraban/8957078 to your computer and use it in GitHub Desktop.
Write-only file uploads for PHP server
<?php
define("UPLOAD_DIR", "/tmp/pobox-uploads/");
define("CODE", "secretcodehere");
if ($_SERVER['REQUEST_METHOD'] == "POST") {
if ($_POST["code"] !== CODE) {
die("upload denied: illegal code");
}
if (!(is_dir(UPLOAD_DIR) || mkdir(UPLOAD_DIR, 0700))) {
die("couldn't create upload dir " . UPLOAD_DIR);
}
$file_name = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_temp = $_FILES['file']['tmp_name'];
$file_error = $_FILES['file']['error'];
$new_name = 'pobox-upload-' . date('Y-m-d_H.i.s') . '_' . $file_name . '.upload';
if ($file_size <= 20 * 1024 * 1024) {
if(move_uploaded_file($file_temp, UPLOAD_DIR . $new_name)) {
echo 'File uploaded: '.$file_name;
} else {
die('Error: '.$file_error);
}
} else {
die("This file is too big!");
}
} else {
?>
<form method=post enctype="multipart/form-data">
<input type=file name=file>
<p>Code: <input name=code>
<p> <input type=submit>
</form>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment