/** * Read one char * * @return string the character read * @throws io.IOException in case of an error */ public function readChar() { if (FALSE === ($result = gzgetc($this->_fd))) { throw new IOException('readChar() cannot read ' . $bytes . ' bytes from ' . $this->uri); } return $result; }
/** * Reads (and decompresses) a (compressed) file into a string * * @param string the path to the file * @param string the MIME type of the file, if empty MIME type is autodetected * * @global array the phpMyAdmin configuration * * @return string the content of the file or * boolean FALSE in case of an error. */ function PMA_readFile($path, $mime = '') { global $cfg; if (!file_exists($path)) { return FALSE; } switch ($mime) { case '': $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $test = fread($file, 3); fclose($file); if ($test[0] == chr(31) && $test[1] == chr(139)) { return PMA_readFile($path, 'application/x-gzip'); } if ($test == 'BZh') { return PMA_readFile($path, 'application/x-bzip'); } return PMA_readFile($path, 'text/plain'); case 'text/plain': $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $content = fread($file, filesize($path)); fclose($file); break; case 'application/x-gzip': if ($cfg['GZipDump'] && @function_exists('gzopen')) { $file = @gzopen($path, 'rb'); if (!$file) { return FALSE; } $content = ''; while (!gzeof($file)) { $content .= gzgetc($file); } gzclose($file); } else { return FALSE; } break; case 'application/x-bzip': if ($cfg['BZipDump'] && @function_exists('bzdecompress')) { $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $content = fread($file, filesize($path)); fclose($file); $content = bzdecompress($content); } else { return FALSE; } break; default: return FALSE; } return $content; }
$zipped = gzencode("testing gzencode"); $tmpfile = tempnam('/tmp', 'vmzlibtest'); $f = fopen($tmpfile, "w"); fwrite($f, $zipped); fclose($f); var_dump(readgzfile($tmpfile)); $zipped = gzencode("testing gzencode"); VS(gzdecode($zipped), "testing gzencode"); $f = gzopen($tmpfile, "w"); VERIFY($f !== false); gzputs($f, "testing gzputs\n"); gzwrite($f, "<html>testing gzwrite</html>\n"); gzclose($f); $f = gzopen($tmpfile, "r"); VS(gzread($f, 7), "testing"); VS(gzgetc($f), " "); VS(gzgets($f), "gzputs\n"); VS(gzgetss($f), "testing gzwrite\n"); VS(gztell($f), 44); VERIFY(gzeof($f)); VERIFY(gzrewind($f)); VS(gztell($f), 0); VERIFY(!gzeof($f)); gzseek($f, -7, SEEK_END); VS(gzgets($f), "testing gzputs\n"); gzclose($f); $f = gzopen(__DIR__ . "/test_ext_zlib.gz", "r"); gzpassthru($f); $compressable = str_repeat('A', 1024); $s = $compressable; $t = nzcompress($s);
/** * Get character from gz-file pointer * * @param resource $zp The gz-file pointer. It must be valid, and must point to a file * successfully opened by gzopen. * * @return string */ public function gzgetc($zp) : string { return gzgetc($zp); }
<?php $f = dirname(__FILE__) . "/004.txt.gz"; $h = gzopen($f, 'r'); $extra_arg = 'nothing'; var_dump(gzgetc($h, $extra_arg)); var_dump(gzgetc()); gzclose($h); ?> ===DONE===
/** * Reads (and decompresses) a (compressed) file into a string * * @param string the path to the file * @param string the MIME type of the file, if empty MIME type is autodetected * * @return string the content of the file or * boolean FALSE in case of an error. */ function _read_sql_file($path, $mime = '') { if (!file_exists($path)) { return FALSE; } switch ($mime) { case '': $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $test = fread($file, 3); fclose($file); if ($test[0] == chr(31) && $test[1] == chr(139)) { return $this->_read_sql_file($path, 'application/x-gzip'); } if ($test == 'BZh') { return $this->_read_sql_file($path, 'application/x-bzip'); } if ($test == 'PK' . chr(3)) { return $this->_read_sql_file($path, 'application/zip'); } return $this->_read_sql_file($path, 'text/plain'); case 'text/plain': $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $content = fread($file, filesize($path)); fclose($file); break; case 'application/x-gzip': if (@function_exists('gzopen')) { $file = @gzopen($path, 'rb'); if (!$file) { return FALSE; } $content = ''; while (!gzeof($file)) { $content .= gzgetc($file); } gzclose($file); } else { return FALSE; } break; case 'application/x-bzip': if (@function_exists('bzdecompress')) { $file = @fopen($path, 'rb'); if (!$file) { return FALSE; } $content = fread($file, filesize($path)); fclose($file); $content = bzdecompress($content); } else { return FALSE; } break; case 'application/zip': // FIXME: need to add decompress code /* */ break; default: return FALSE; } return $content; }
function index($project, $dbconf) { @set_time_limit(0); /*** Load database ***/ require APPPATH . '../' . $project . '/config/database.php'; $this->load->database($db[$dbconf]); /*** Parse file ***/ $error = ""; $msg = ""; $fileElementName = 'fileToUpload'; if (!empty($_FILES[$fileElementName]['error'])) { switch ($_FILES[$fileElementName]['error']) { case '1': $error = 'The uploaded file exceeds the upload_max_filesize directive in php.ini'; break; case '2': $error = 'The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form'; break; case '3': $error = 'The uploaded file was only partially uploaded'; break; case '4': $error = 'No file was uploaded.'; break; case '6': $error = 'Missing a temporary folder'; break; case '7': $error = 'Failed to write file to disk'; break; case '8': $error = 'File upload stopped by extension'; break; case '999': default: $error = 'No error code avaiable'; } echo $error; } elseif (empty($_FILES['fileToUpload']['tmp_name']) || $_FILES['fileToUpload']['tmp_name'] == 'none') { $error = 'No file was uploaded..'; } else { $this->load->helper("file"); $_FILES['fileToUpload']['name']; $type = get_mime_by_extension($_FILES['fileToUpload']['name']); switch ($type) { case "application/x-zip": $content = $this->_unzip($_FILES['fileToUpload']['tmp_name']); break; case "application/x-gzip": $gz = gzopen($_FILES['fileToUpload']['tmp_name'], 'r'); $content = ""; while (!gzeof($gz)) { $content .= gzgetc($gz); } gzclose($gz); break; default: $content = file_get_contents($_FILES['fileToUpload']['tmp_name']); break; } $items = preg_split("/;(\r?\n|\r)/", $content); if (count($items) > 0) { $this->load->database(); foreach ($items as $item) { if (trim($item) != "") { $this->db->query($item); } } } @unlink($_FILES['fileToUpload']); } }
public function dxcc() { $this->update_status("Downloading file"); // give it 5 minutes... set_time_limit(600); // Load Migration data if any. $this->load->library('migration'); $this->fix_migrations(); $this->migration->latest(); // Download latest file. $url = "https://secure.clublog.org/cty.php?api=a11c3235cd74b88212ce726857056939d52372bd"; $gz = gzopen($url, 'r'); $data = ""; while (!gzeof($gz)) { $data .= gzgetc($gz); } gzclose($gz); file_put_contents('./updates/cty.xml', $data); // Clear the tables, ready for new data $this->db->empty_table("dxcc_entities"); $this->db->empty_table("dxcc_exceptions"); $this->db->empty_table("dxcc_prefixes"); $this->update_status(); // Parse the three sections of the file and update the tables $this->db->trans_start(); $this->dxcc_entities(); $this->dxcc_exceptions(); $this->dxcc_prefixes(); $this->db->trans_complete(); $this->update_status("DONE"); }
public function getChar($zp = '') { if (!is_resource($zp)) { return Error::set(lang('Error', 'resourceParameter', '1.(zp)')); } return gzgetc($zp); }
public function dxcc() { // Load Migration data if any. $this->load->library('migration'); if (!$this->migration->latest()) { show_error($this->migration->error_string()); } // Download latest file. $url = "https://secure.clublog.org/cty.php?api=a11c3235cd74b88212ce726857056939d52372bd"; $gz = gzopen($url, 'r'); $data = ""; while (!gzeof($gz)) { $data .= gzgetc($gz); } gzclose($gz); file_put_contents('./updates/cty.xml', $data); // Set timeout to unlimited set_time_limit(0); // Load Database connectors $this->load->model('dxcc'); // Load the cty file $xml_data = simplexml_load_file("updates/cty.xml"); $this->dxcc->empty_table("dxcc"); echo "<h2>Prefix List</h2>"; echo "<table>"; echo "<tr>"; echo "<td>Prefix</td>"; echo "<td>Country Name</td>"; echo "<td>DXCC Expire Date</td>"; echo "</tr>"; foreach ($xml_data->prefixes as $prefixs) { foreach ($prefixs->prefix as $callsign) { $endinfo = strtotime($callsign->end); if ($endinfo) { $end_date = date('Y-m-d H:i:s', $endinfo); } else { $end_date = ""; } if (!$callsign->cqz) { $data = array('prefix' => (string) $callsign->call, 'name' => (string) $callsign->entity); } else { $data = array('prefix' => (string) $callsign->call, 'name' => (string) $callsign->entity, 'cqz' => (string) $callsign->cqz, 'ituz' => (string) $callsign->ituz, 'cont' => (string) $callsign->cont, 'long' => (string) $callsign->long, 'lat' => (string) $callsign->lat, 'end_date' => $end_date); } echo "<tr>"; echo "<td>" . $callsign->call . "</td>"; echo "<td>" . ucwords(strtolower($callsign->entity)) . "</td>"; echo "<td>" . $end_date . "</td>"; echo "<td>" . $callsign->deleted . "</td>"; echo "</tr>"; $this->db->insert('dxcc', $data); } } echo "<table>"; // empty table $this->dxcc->empty_table("dxccexceptions"); echo "<h2>Exceptions</h2>"; echo "<table>"; foreach ($xml_data->exceptions as $exceptions) { foreach ($exceptions->exception as $callsign) { echo "<tr>"; echo "<td>" . $callsign->call . "</td>"; echo "<td>" . $callsign->entity . "</td>"; echo "</tr>"; if (!$callsign->start) { $data = array('prefix' => (string) $callsign->call, 'name' => (string) $callsign->entity, 'cqz' => (string) $callsign->cqz, 'ituz' => (string) $callsign->ituz, 'cont' => (string) $callsign->cont, 'long' => (string) $callsign->long, 'lat' => (string) $callsign->lat); } else { $startinfo = strtotime($callsign->start); if ($startinfo) { $start = date('Y-m-d H:i:s', $startinfo); } else { $start = ""; } $endinfo = strtotime($callsign->end); if ($endinfo) { $end = date('Y-m-d H:i:s', $endinfo); } else { $end = ""; } $data = array('prefix' => (string) $callsign->call, 'name' => (string) $callsign->entity, 'cqz' => (string) $callsign->cqz, 'ituz' => (string) $callsign->ituz, 'cont' => (string) $callsign->cont, 'long' => (string) $callsign->long, 'lat' => (string) $callsign->lat, 'start' => $start, 'end' => $end); } $this->db->insert('dxccexceptions', $data); } } echo "<table>"; }