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:
parent
cdfc70faed
commit
1b8c0c6f77
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue