GRAYBYTE WORDPRESS FILE MANAGER9745

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /home/giriqfky/public_html/Barga/application/helpers/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/giriqfky/public_html/Barga/application/helpers//csv_helper.php
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('array_to_csv'))
{
	function array_to_csv($array, $download = "")
	{
		if ($download != "")
		{	
			header('Content-Type: text/csv');
			header('Content-Disposition: attachement; filename="' . $download . '"');
		}		

		ob_start();
		$f = fopen('php://output', 'w') or show_error("Can't open php://output");
		$n = 0;		
		foreach ($array as $line)
		{
			$n++;
			if ( ! fputcsv($f, $line))
			{
				show_error("Can't write line $n: $line");
			}
		}
		fclose($f) or show_error("Can't close php://output");
		$str = ob_get_contents();
		ob_end_clean();

		if ($download == "")
		{
			return $str;	
		}
		else
		{	
			echo $str;
		}		
	}
}

// ------------------------------------------------------------------------

/**
 * Query to CSV
 *
 * download == "" -> return CSV string
 * download == "toto.csv" -> download file toto.csv
 */
if ( ! function_exists('query_to_csv'))
{
	function query_to_csv($query, $headers = TRUE, $download = "")
	{
		if ( ! is_object($query) OR ! method_exists($query, 'list_fields'))
		{
			show_error('invalid query');
		}
		
		$array = array();
		
		if ($headers)
		{
			$line = array();
			foreach ($query->list_fields() as $name)
			{
				$line[] = $name;
			}
			$array[] = $line;
		}
		
		foreach ($query->result_array() as $row)
		{
			$line = array();
			foreach ($row as $item)
			{
				$line[] = $item;
			}
			$array[] = $line;
		}

		echo array_to_csv($array, $download);
	}
}

function csv_to_array($filename = '', $delimiter = ',', $asHash = true) {
    if (!(is_readable($filename) || (($status = get_headers($filename)) && strpos($status[0], '200')))) {
        return FALSE;
    }
 
    $header = NULL;
    $data = array();
    if (($handle = fopen($filename, 'r')) !== FALSE) {
        if ($asHash) {
            while ($row = fgetcsv($handle, 0, $delimiter)) {
                if (!$header) {
                    $header = $row;
                } else {
                    $data[] = array_combine($header, $row);
                }
            }
        } else {
            while ($row = fgetcsv($handle, 0, $delimiter)) {
                $data[] = $row;
            }
        }
 
        fclose($handle);
    }
 
    return $data;
}

/* End of file csv_helper.php */
/* Location: ./system/helpers/csv_helper.php */

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
July 27 2024 00:19:25
giriqfky / giriqfky
0755
csv_helper.php
2.31 KB
July 27 2024 00:19:25
giriqfky / giriqfky
0644
drop_down_helper.php
2.148 KB
July 27 2024 00:19:25
giriqfky / giriqfky
0644
general_helper.php
37.263 KB
July 27 2024 00:19:25
giriqfky / giriqfky
0644
index.html
0.128 KB
July 27 2024 00:19:25
giriqfky / giriqfky
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF