| Server IP : 104.26.4.103 / Your IP : 216.73.216.4 Web Server : nginx/1.27.1 System : Linux in-5 5.15.0-143-generic #153-Ubuntu SMP Fri Jun 13 19:10:45 UTC 2025 x86_64 User : arabianexpress ( 1872) PHP Version : 8.0.30 Disable Function : exec,passthru,shell_exec,system,proc_open,popen,parse_ini_file,show_source MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /storage/v9321/leapdubai/public_html/wp-content/plugins/kirki/app/Supports/ |
Upload File : |
<?php
namespace Kirki\App\Supports;
defined('ABSPATH') || exit;
use Kirki\Framework\Supports\Facades\File as FileHelper;
use PclZip;
use function Kirki\App\get_upload_directory;
use function Kirki\Framework\Polyfill\array_last;
class FileHandler
{
public static function get_temp_folder_path()
{
$temp_folder = 'kirki_temp';
return get_upload_directory() . '/' . $temp_folder;
}
/**
* Download zip file from remote server
*
* @param string $remote_file
* @param string $file_name
* @return string|false -- if failed return false
*/
public static function download_zip_from_remote(string $remote_file, string $file_name)
{
$file_ext = explode('.', $remote_file); // ['file', 'ext']
$file_ext = strtolower(array_last($file_ext)); // 'ext'
$allowed = ['zip'];
if (!in_array($file_ext, $allowed)) {
return false;
}
// Download the file from the remote server.
// Create a stream context to disable SSL verification
$options = [
"http" => [
"method" => "GET",
"header" => "User-Agent: WordPress\r\n"
],
"ssl" => [
"verify_peer" => false, // Disable verification of the peer's certificate
"verify_peer_name" => false // Disable verification of the peer's name
]
];
$context = @stream_context_create($options);
$file_contents = @file_get_contents($remote_file, false, $context);
if ($file_contents === false) {
return false;
}
// Save the file locally.
// Local path to save the downloaded file.
$local_file = get_upload_directory() . '/' . $file_name;
$is_downloaded = FileHelper::put($local_file, $file_contents);
if (!$is_downloaded) {
return false;
}
return $local_file;
}
/**
* @return array|false
* return false on failure
*/
public static function extract_zip_file(string $zip_file_path, string $destination_dir)
{
if (!class_exists('PclZip')) {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';
}
if (FileHelper::missing($zip_file_path)) {
return false;
}
if (!FileHelper::is_directory($destination_dir)) {
FileHelper::make_dir($destination_dir);
}
$zip = new PclZip($zip_file_path);
$result = $zip->extract(
PCLZIP_OPT_PATH,
$destination_dir
);
if (is_array($result)) {
return $result;
}
return false;
}
}