echo 'sha384-' . base64_encode(hash_file('sha384', 'path-to-file', true));
// или
echo 'sha384-' . base64_encode(hash('sha384', file_get_contents('path-to-file'), true));
<script type="text/javascript"
src="https://site.com/file.js"
integrity="sha384-<?php echo base64_encode(openssl_digest(file_get_contents('/assets/file.js'), 'sha384', true)); ?>"
crossorigin="anonymous"></script>
echo base64_encode(openssl_digest(file_get_contents('/assets/file.js'), 'sha384', true));