示例#1
0
		<td>上传时间</td>
		<td width="40">操作</td>
	</tr>
	';
foreach ($result as $row) {
    /*
    if( $row["remote"] ){
    	$link = url_merge(str_replace(FTP_ROOT,FTP_SITE,$row['name']));	
    	$name = str_replace(FTP_ROOT,'',$row['name']);
    }else{
    	$link = (VI_BASE.$row['name']);
    	$name = $row['name'];
    }
    */
    if ($row["remote"]) {
        $link = url_merge(str_replace(FTP_ROOT, FTP_SITE, $row['name']));
        $name = str_replace(FTP_ROOT, '', $row['name']);
    } else {
        $name = $link = $row['name'];
    }
    echo "<tr class='" . zebra($i, array("line", "band")) . "'>";
    echo "<td><input name='id' type='checkbox' class='checkbox' id='id' value='" . $row['id'] . "'></td>";
    echo '<td title="' . $row['name'] . '" id="file-' . $row['id'] . '"><var data-type="type" data-link="?s=type&q=' . $row["type"] . '">' . $row["type"] . '</var><a id="url-' . $row['id'] . '" href="' . $link . '" target="_blank">' . format_url($row['name'], 40) . '</a></td>';
    echo "<td><a href='?s=account&q=" . urlencode($row['account']) . "'>" . $row['account'] . "</a></td>";
    echo "<td>" . $row["input"] . "</td>";
    echo "<td>" . sizecount($row["size"]) . "</td>";
    echo "<td><a href='?r=" . $row["remote"] . "'>" . $_G['project']['attach'][$row["remote"]] . "</a></td>";
    echo "<td>" . ($row["width"] ? $row["width"] . "*" . $row["height"] : "") . "</td>";
    echo "<td>" . date("Y-m-d H:i:s", $row['dateline']) . "</td>";
    echo '<td><button type="button" class="normal" data-url="?action=delete&list=' . $row["id"] . '">删除</button></td>';
}
示例#2
0
文件: attach.php 项目: a195474368/ejw
 public static function file_upload($field, $index = -1, $type, $config)
 {
     global $_G;
     //本地文件名称
     $local = $index > -1 && is_int($index) ? $_FILES[$field]["name"][$index] : $_FILES[$field]["name"];
     //错误信息
     $error = $index > -1 && is_int($index) ? $_FILES[$field]["error"][$index] : $_FILES[$field]["error"];
     //没有上传文件或出错
     if (!$local || $error) {
         return 1;
     }
     //文件大小
     $size = $index > -1 && is_int($index) ? $_FILES[$field]["size"][$index] : $_FILES[$field]["size"];
     //临时名称
     $temp = $index > -1 && is_int($index) ? $_FILES[$field]["tmp_name"][$index] : $_FILES[$field]["tmp_name"];
     //当前文件类型
     $mime = fileext($local);
     //不被允许的类型
     if (!in_array($mime, $type)) {
         return 2;
     }
     //搜索所在分类
     foreach ($_G['upload'] as $item => $array) {
         //定位到分类
         if (in_array($mime, $array)) {
             //文件分类
             $cate = $item;
             break;
         }
     }
     //文件类型不在上传配置中
     if (!$cate) {
         return 3;
     }
     //根文件夹
     $folder = VI_ROOT . 'attach/' . $cate;
     //创建子文件夹
     if (!file_exists($folder)) {
         create_dir($folder);
     }
     //限制文件大小
     if (is_int($config["size"]) && $size > $config["size"]) {
         return 4;
     }
     /*******保存文件_开始*******/
     //创建目录
     $path = create_dir($folder . "/" . date("Y/md/"));
     //生成文件名
     $name = $path . date("H-i-s-") . mt_rand() . "." . $mime;
     //移动文件失败
     if (!copy(realpath($temp), $name)) {
         return 5;
     }
     /*******保存文件_结束*******/
     //图片则计算尺寸
     $width = $height = 0;
     if ($cate == "image") {
         //返回图片尺寸
         list($width, $height) = getimagesize($name);
         //包含类
         require_once VI_ROOT . 'source/class/thumb.php';
         //生成缩略图
         if (is_array($config["thumb"])) {
             //缩略图
             $t = new ThumbHandler();
             //源图片地址
             $t->setSrcImg($name);
             //输出文件名
             $t->setDstImg(str_replace("." . $mime, "-thumb." . $mime, $name));
             //生成图片
             $t->createImg($config["thumb"][0], $config["thumb"][1]);
         }
         //生成组图
         if (is_array($config["group"])) {
             foreach ($config["group"] as $g) {
                 if (is_array($g)) {
                     //缩略图
                     $t = new ThumbHandler();
                     //源图片地址
                     $t->setSrcImg($name);
                     //输出文件名
                     $t->setDstImg(str_replace("." . $mime, "-" . $g[0] . "-" . $g[1] . "." . $mime, $name));
                     //生成图片
                     $t->createImg($g[0], $g[1]);
                 }
             }
         }
         //生成裁切图
         if (is_array($config["crop"])) {
             //缩略图
             $t = new ThumbHandler();
             //源图片地址
             $t->setSrcImg($name);
             //输出文件名
             $t->setDstImg($name);
             //生成图片
             $t->createImg($config["crop"][0], $config["crop"][1]);
         }
     }
     //exit(  );
     //合并路径
     $file = url_merge(str_replace(VI_ROOT, "", VI_BASE . $name));
     //echo $file;
     //exit($file);
     //写入数据库
     $sql = "INSERT INTO `sys:attach`(name,input,dateline,type,size,ip,width,height,remote) values('" . $file . "','" . $field . "'," . time() . ",'" . $mime . "',{$size},'" . GetIP() . "',{$width},{$height},0)";
     System::$db->execute($sql);
     //返回文件名
     return $file;
 }