fipamo/brain/utility/FileUploader.php
Are0h 63eaba08e2 Added config for PHP formatting (PSR2)
I needed some consistent php formatting, so I plugged in a php fixer
config and then reformatted all PHP files so it's all consistent.

Fixed an ID issue with the page-edit template that was causing page
editing to fail.
2022-05-16 17:41:15 -07:00

33 lines
1 KiB
PHP

<?php
namespace brain\utility;
class FileUploader
{
public static function uploadFile(string $directory, $file)
{
$response = [];
try {
if (!is_dir($directory)) {
// Directory does not exist, so lets create it.
mkdir($directory, 0755, true);
}
// $upload = move_uploaded_file($file->getClientFileName(), $directory);
// $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
// see http://php.net/manual/en/function.random-bytes.php
// $basename = bin2hex(random_bytes(8));
// $filename = sprintf("%s.%0.8s", $basename, $extension);
// echo "**FILE** " . $file->getClientFileName();
$file->moveTo($directory . '/' . urlencode($file->getClientFileName()));
} catch (RuntimeException $e) {
echo 'ERROR ' . $e->getMessage();
// echo "failed to upload image: " . $e->getMessage();
// throw new Error("Failed to upload image file");
}
}
}