Skip to content

Instantly share code, notes, and snippets.

@tuckbloor
Created May 12, 2023 07:21
Show Gist options
  • Save tuckbloor/0fdb8662515d6a928515a83372a118e4 to your computer and use it in GitHub Desktop.
Save tuckbloor/0fdb8662515d6a928515a83372a118e4 to your computer and use it in GitHub Desktop.
php file upload protect against phat
if ($_FILES['file']['error'] !== UPLOAD_ERR_OK) {
// Handle upload error
}
$filePath = $_FILES['file']['tmp_name'];
$signature = file_get_contents('phar://' . $filePath . '/.signature');
if ($signature !== 'GBMB') {
// Invalid PHAR file
}
// Move the uploaded file to a permanent location
$uploadDir = '/path/to/upload/directory/';
$fileName = $_FILES['file']['name'];
$filePath = $uploadDir . $fileName;
if (!move_uploaded_file($_FILES['file']['tmp_name'], $filePath)) {
// Handle file move error
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment