Tmpfiles in shared hostings

Addins support for shared hostings that doesnt allow to create tmp files but allow to create individual files
This commit is contained in:
John F. Arroyave Gutiérrez 2023-06-30 07:56:33 -05:00 committed by GitHub
parent cdfc70faed
commit 1b8c0c6f77
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,9 +5,24 @@ class TmpFile {
var $size;
function __construct() {
$this->handler = tmpfile();
if (function_exists('tmpfile'))
$this->handler = tmpfile();
else {
$temp_file_template = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$temp_file='';
for($i=0;$i<20;$i++)
$temp_file .= $temp_file_template[rand(0,strlen($temp_file_template)-1)];
$this->handler = fopen($temp_file, "w+");
}
}
function __destruct() {
if (!function_exists('tmpfile')) {
$temp_file_metadata = stream_get_meta_data ( $this->handler );
unlink ($temp_file_metadata['uri']);
}
}
function write($contents) {
$this->size += strlen($contents);
fwrite($this->handler, $contents);