本文整理汇总了PHP中waFiles::convert方法的典型用法代码示例。如果您正苦于以下问题:PHP waFiles::convert方法的具体用法?PHP waFiles::convert怎么用?PHP waFiles::convert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waFiles
的用法示例。
在下文中一共展示了waFiles::convert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: open
private function open()
{
if ($this->file && file_exists($this->file)) {
$this->files();
$extension = pathinfo($this->file, PATHINFO_EXTENSION);
$file = basename($this->file, '.' . $extension);
if (pathinfo($file, PATHINFO_EXTENSION) != 'csv') {
$file .= '.csv';
}
$path = pathinfo($this->file, PATHINFO_DIRNAME) . '/';
$file = $path . $file;
switch ($extension) {
case 'gz':
if (extension_loaded('zlib')) {
if (function_exists('gzopen')) {
if (($src = gzopen($this->file, 'rb')) && ($dst = fopen($file, 'wb'))) {
stream_copy_to_stream($src, $dst);
gzclose($src);
fclose($dst);
$this->file = $file;
} else {
throw new waException("Error while read gz file");
}
$this->open();
break;
} elseif (in_array('compress.zlib', stream_get_wrappers())) {
$this->fp = fopen('compress.zlib://' . $this->file, 'rb');
} else {
throw new waException("Unsupported file extension");
}
} else {
throw new waException("Unsupported file extension");
}
$this->fsize = filesize($this->file);
break;
case 'zip':
if (function_exists('zip_open') && ($zip = zip_open($this->file)) && is_resource($zip) && ($zip_entry = zip_read($zip))) {
//dummy read first file;
$file = $path . waLocale::transliterate(basename(zip_entry_name($zip_entry)));
$zip_fs = zip_entry_filesize($zip_entry);
if ($z = fopen($file, "w")) {
$size = 0;
while ($zz = zip_entry_read($zip_entry, max(0, min(4096, $zip_fs - $size)))) {
fwrite($z, $zz);
$size += 1024;
}
fclose($z);
zip_entry_close($zip_entry);
zip_close($zip);
$this->file = $file;
$this->files();
} else {
zip_entry_close($zip_entry);
zip_close($zip);
throw new waException("Error while read zip file");
}
$this->open();
} else {
throw new waException("Error while read zip file");
}
break;
default:
if (is_array($this->encoding) || $this->encoding == 'auto') {
$this->fp = fopen($this->file, "rb");
if (!$this->fp) {
throw new waException("error while open CSV file");
}
$chunk = fread($this->fp, 4096);
if (is_array($this->encoding)) {
$this->encoding = mb_detect_encoding($chunk, $this->encoding);
} else {
$this->encoding = mb_detect_encoding($chunk);
}
if (strtolower($this->encoding) == 'utf-8') {
fseek($this->fp, 0);
}
}
if (strtolower($this->encoding) != 'utf-8') {
if ($this->fp) {
fclose($this->fp);
unset($this->fp);
}
if ($file = waFiles::convert($this->file, $this->encoding)) {
$this->encoding = 'utf-8';
$this->file = $file;
$this->files();
$this->fp = fopen($this->file, "rb");
} else {
throw new waException("Error while convert file encoding");
}
} elseif (!$this->fp) {
$this->fp = fopen($this->file, "rb");
}
$this->fsize = filesize($this->file);
break;
}
}
}