From 1b8c0c6f77513ae0d0a2d121e889501ce0cb0056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20F=2E=20Arroyave=20Guti=C3=A9rrez?= Date: Fri, 30 Jun 2023 07:56:33 -0500 Subject: [PATCH] Tmpfiles in shared hostings Addins support for shared hostings that doesnt allow to create tmp files but allow to create individual files --- adminer/include/tmpfile.inc.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/adminer/include/tmpfile.inc.php b/adminer/include/tmpfile.inc.php index 79baf17b..acb2ae84 100644 --- a/adminer/include/tmpfile.inc.php +++ b/adminer/include/tmpfile.inc.php @@ -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);