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 "failed to upload image: " . $e->getMessage(); throw new Error("Failed to upload image file"); } } }