/** * csv format * 0 开头是不留空,以行为单位。 * 1 可含或不含列名,含列名则居文件第一行。 * 2 一行数据不垮行,无空行。 * 3 以半角符号,作分隔符,列为空也要表达其存在。 * 4 列内容如存在半角逗号(即,)则用半角引号(即"")将该字段值包含起来。(ad中有可能出现逗号:"\""+ ad + "\"" ) * 5 列内容如存在半角引号(即")则应替换成半角双引号("")转义。 * 6 文件读写时引号,逗号操作规则互逆。 * 7 内码格式不限,可为ASCII、Unicode或者其他。 * * output csv format data * @param null $filename * @return bool */ public function csv($filename = null) { $view = $this->initView(); $template = $this->template(null, null, '.csv'); $content = $view->render($template, true); $content = mb_convert_encoding($content, 'gbk', 'utf-8'); if (empty($filename)) { $filename = Str::rand(8) . '.csv'; } Response::download($filename); echo $content; return true; }
public function upload() { $this->savePath = '/' . date('Ym'); if (!is_dir($this->fileDir . $this->savePath) && !mkdir($this->fileDir . $this->savePath)) { throw new Exception(sprintf('目录 %s 不存在', $this->fileDir . $this->savePath), 403); } @chmod($this->fileDir . $this->savePath); if (!is_writeable($this->fileDir . $this->savePath)) { throw new Exception(sprintf('目录 %s 不可写', $this->fileDir . $this->savePath), 403); } foreach ($this->fileArr as $k => $file) { if (!self::isUploadedFile($file['tmp_name'])) { $this->resultArr[$k]['errno'] = 1; $this->resultArr[$k]['description'] = '文件上传失败'; continue; } $suffix = Str::suffix($file['name']); $isImage = in_array($suffix, $this->allowImageExtArr); if ($this->onlyAllowImage && !$isImage) { $this->resultArr[$k]['errno'] = 2; $this->resultArr[$k]['description'] = '不允许上传非图片类型文件'; continue; } if (!in_array($suffix, $this->allowFileExtArr)) { $this->resultArr[$k]['errno'] = 3; $this->resultArr[$k]['description'] = '类型文件不允许'; continue; } if ($file['size'] > $this->maxFileSize) { $this->resultArr[$k]['errno'] = 4; $this->resultArr[$k]['description'] = '文件大小超过限制'; continue; } $filename = date('d') . Str::random(6) . '.' . $suffix; $target = $this->fileDir . $this->savePath . '/' . $filename; if (move_uploaded_file($file['tmp_name'], $target) || @copy($file['tmp_name'], $target)) { $this->resultArr[$k]['errno'] = 0; $this->resultArr[$k]['description'] = '文件上传成功'; $this->uploadedFileArr[] = array('name' => $file['name'], 'url' => $this->savePath . '/' . $filename, 'type' => $file['type'], 'size' => $file['size'], 'description' => $file['description'], 'is_image' => $isImage); } else { $this->resultArr[$k]['errno'] = 5; $this->resultArr[$k]['description'] = '文件上传失败'; } } return $this; }
public static function convert($content, $stat = "http://ed2k.shortypower.org/?hash=", $no = '') { $no == '' && ($no = Str::rand(4)); $totalsize = 0; $extArr = array(); $c = '<table class="emule table table-striped" style="font-size:12px;" id="table' . $no . '"><thead><tr><th>SimCD 电驴下载 <span class="pull-right">建议使用迅雷离线下载、QQ旋风极速下载</span></th><th width="80"></th></tr></thead><tbody>'; $num = 0; $content = preg_replace("/(?<!ed2k=)(?<!ed2k=[\"\\'])(?<!href=)(?<!href=[\"\\'])ed2k:\\/\\/\\|file\\|.+?\\|\\/(?!\\|)/i", "\n\\0\n", $content); preg_match_all("/^.+\$/m", $content, $lines); if (empty($lines[0])) { return ''; } $arr = []; foreach ($lines[0] as $myline) { $myline .= '/'; preg_match("/(?<!ed2k=)(?<!ed2k=[\"\\'])(?<!href=)(?<!href=[\"\\'])ed2k:\\/\\/\\|(file)\\|([^|]+\\|[0-9]+\\|[a-f0-9]+)\\|(?:[a-z0-9=|\\/]+)?/i", $myline, $matches); //var_dump($matches); /* preg_match ( "/(?<!ed2k=)(?<!ed2k=[\"\'])(?<!href=)(?<!href=[\"\'])ed2k:\/\/\|(file)\|(.+?)\|\/(?!\|)/i", $myline, $matches ); */ if (count($matches) != 0) { $pieces = explode("|", $matches[2]); $ed2k = 'ed2k://|file|' . implode('|', $pieces) . '|/'; $ed2k = self::normalization($ed2k); $file = self::name($ed2k); if (strpos($file, '.')) { $ext = Str::suffix($file); array_push($extArr, $ext); } $size = $pieces[1]; $totalsize += $size; $size = Str::size($size); $hash = $pieces[2]; if (isset($arr[$hash])) { continue; } $num++; $arr[$hash] = 1; $c .= '<tr><td style="word-break:break-all;"><input type="checkbox" class="chk" name="chk' . $no . '[]" value="' . $ed2k . '" onclick="ed2k.check(\'' . $no . '\',event);" checked="checked" /> <a rel="nofollow" href="' . $ed2k . '">' . $file . '</a>'; if ($stat != '') { $c .= ' <a href="' . $stat . $hash . '" target="_blank">' . '查源' . '</a>'; } $c .= '</td><td>' . $size . '</td></tr>'; } else { $myline = preg_replace("/<p>|<\\/p>|<br\\s\\/>|<br\\/>|<br>/i", "", $myline); $myline = trim($myline); if ($myline !== "") { $c .= '<tr><td colspan="2">' . $myline . ' </td></tr>'; } } } $totalsize = Str::size($totalsize); $c .= '<tr><td><label for="chkall' . $no . '" style="float:left;display:inline"><input type="checkbox" class="chkall" id="chkall' . $no . '" onclick="ed2k.checkAll(\'' . $no . '\',this.checked)" checked="checked" /> 全选' . '</label>'; if ($num >= 2) { $c .= '<ul style="font-size:12px;float:left;margin:0 20px" class="unstyled"><li><label class="namefilter" for="namefilter' . $no . '" style="display:inline">' . '文件名选择' . ':</label>'; $extArr = array_unique($extArr); foreach ($extArr as $ext) { $c .= ' <label style="display:inline" for="chktype' . $ext . '-' . $no . '"><input type="checkbox" value="' . $ext . '" name="chktype' . $no . '[]" id="chktype' . $ext . '-' . $no . '" onclick="ed2k.typeFilter(\'' . $no . '\',this.value,this.checked)" />' . strtoupper($ext) . '</label>'; } $c .= ' <input style="width:160px;padding:0px;font-size:12px;" type="text" id="namefilter' . $no . '" onkeyup="ed2k.filter(\'' . $no . '\')" /></li>'; $c .= '<li><label style="display:inline" for="sizefilter' . $no . '-1">大小选择:</label><select id="sizesymbol' . $no . '-1" onchange="ed2k.filter(\'' . $no . '\')"> <option selected="selected" value="1">></option> <option value="2"><</option> </select><input style="width:60px;padding:0px;font-size:12px;" type="text" id="sizefilter' . $no . '-1" onkeyup="ed2k.filter(\'' . $no . '\')" /><select id="sizeunit' . $no . '-1" onchange="ed2k.filter(\'' . $no . '\')"> <option value="1073741824">' . 'GB' . '</option> <option selected="selected" value="1048576">' . 'MB' . '</option> <option value="1024">' . 'KB' . '</option> <option value="1">' . 'B' . '</option> </select> && <select id="sizesymbol' . $no . '-2" onchange="ed2k.filter(\'' . $no . '\')"> <option value="1">></option> <option selected="selected" value="2"><</option> </select><input style="width:60px;padding:0px;font-size:12px;" type="text" id="sizefilter' . $no . '-2" onkeyup="ed2k.filter(\'' . $no . '\')" /><select id="sizeunit' . $no . '-2" onchange="ed2k.filter(\'' . $no . '\')"> <option value="1073741824">' . 'GB' . '</option> <option selected="selected" value="1048576">' . 'MB' . '</option> <option value="1024">' . 'KB' . '</option> <option value="1">' . 'B' . '</option> </select></label></li></ul>'; } $c .= '</td><td><span id="totalsize' . $no . '">' . $totalsize . '</span><br />(<span id="totalnum' . $no . '">' . $num . '</span>' . '文件' . ')</td></tr><tr><td colspan="2"> <input type="button" id="copylinks' . $no . '" class="btn btn-success copylinks" title="复制选中链接" value="复制选中链接" /> <span id="copied' . $no . '" style="display:none;" class="text-success">√ 已复制</span> <input type="button" id="downlinks' . $no . '" class="btn btn-danger downlinks" onclick="ed2k.download(\'' . $no . '\')" title="下载选中链接" value="下载选中链接" /> </td></tr> </tbody> </table>'; return $c; }
public static function convert($c) { $c = trim($c); if ('' == $c) { return ''; } $no = Str::rand(4); $arr = explode("\n", $c); $str = '<table class="xunlei table table-striped" style="font-size:12px;"><thead><tr><th>SimCD 迅雷下载<span class="pull-right">建议使用迅雷离线下载、QQ旋风极速下载</span></th></tr></thead><tbody>'; foreach ($arr as $url) { $name = self::name($url); if ('' == $name) { $name = $url; } $thunder = self::encode($url); $str .= '<tr><td style="word-break:break-all;"><input type="checkbox" class="chk" name="chk' . $no . '[]" value="' . $url . '" onclick="thunder.check(\'' . $no . '\');" checked="checked" /> <a rel="nofollow" href="' . $thunder . '">' . $name . '</a></td></tr>'; } $str .= '<tr><td><label for="chkall' . $no . '"><input type="checkbox" class="chkall" id="chkall' . $no . '" onclick="thunder.checkAll(\'' . $no . '\',this.checked,event)" checked="checked" /> 全选' . '</label></td></tr><tr><td><input type="button" id="copylinks' . $no . '" class="btn btn-success copylinks" title="复制选中链接" value="复制选中链接" /> <span id="copied' . $no . '" style="display:none;" class="text-success">√ 已复制</span> </td></tr>'; $str .= '</body></table>'; return $str; }