You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Fipamo/brain/utility/FileUploader.inc.php

33 lines
942 B
PHP

<?php
use Psr\Http\Message\UploadedFileInterface;
//include "brain/data/Auth.inc.php";
class FileUploader
{
public static function uploadFile(
string $directory,
UploadedFileInterface $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);
$file->moveTo($directory . "/" . $file->getClientFileName());
} catch (Error $e) {
echo $e;
//echo "failed to upload image: " . $e->getMessage();
//throw new Error("Failed to upload image file");
}
}
}