分类: 默认分类

  • 加载到底部的一个提示样式

    <view class="end">
      <view class="end-inner">
        <span>我们是有底线的</span>
      </view>
    </view>
    .end{position: relative; width: 750rpx; height: 100rpx;}
    .end::before{position: absolute; left: 0; top: 50%; content: ""; width: 750rpx; height: 0rpx; border-bottom: 1px solid #eee;}
    .end .end-inner{position: absolute; z-index: 9; display: flex; align-items: center; justify-content: center; width: 100%; height: 100%;}
    .end .end-inner span{font-size: 30rpx; color: #bbb; background: #fff; padding: 0 20rpx;}
  • 小程序page页面json设置,下拉刷新等…

    page.json//page.json相当于app.json中的window
    {
      "navigationBarBackgroundColor": "#ffffff",//导航栏背景颜色
      "navigationBarTextStyle": "black",//导航栏标题颜色,仅支持 black/white
      "navigationBarTitleText": "微信接口功能演示",//导航栏标题文字内容
      "backgroundColor": "#eeeeee",//窗口的背景色
      "backgroundTextStyle": "light"//下拉背景字体、loading 图的样式,仅支持 dark/light
      "enablePullDownRefresh": true//是否开启下拉刷新
      "disableScroll": false//设置为 true 则页面整体不能上下滚动;只在 page.json 中有效,无法在 app.json 中设置该项
    }
  • Thinkphp5.1安装过程

    一,首先是通过composer安装thinkphp5.1

    composer create-project topthink/think tp5
    composer create-project topthink/think tp5
    composer create-project topthink/think tp5

    php

  • webuploader插件上传图片

    一,引入文件

    <link rel="stylesheet" href="./webuploader/webuploader.css">
    <script src="./jquery/jquery.js"></script>
    <script src="./webuploader/webuploader.min.js"></script>

    二,html

    <style>
    	.thumbnail{width: 300px;}
    	.progress{width: 100%; height: 4px; background-color: red;}
    	.progress span{display: block; height: 4px; background-color: blue;}
    </style>
    <!--dom结构部分-->
    <div id="uploader-demo">
      <!--用来存放item-->
      <div id="fileList" class="uploader-list"></div>
      <div id="filePicker">选择图片</div>
    </div>

    三,javascript

    // 初始化Web Uploader
    var uploader = WebUploader.create({
    
        // 选完文件后,是否自动上传。
        auto: true,
    
        // swf文件路径
        swf: './webuploader/Uploader.swf',
    
        // 文件接收服务端。
        server: './upload.active.php',
    
        // 选择文件的按钮。可选。
        // 内部根据当前运行是创建,可能是input元素,也可能是flash.
        pick: '#filePicker',
    
        // 只允许选择图片文件。
        accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
        }
    });
    // 当有文件添加进来的时候
    uploader.on( 'fileQueued', function( file ) {
        var $li = $(
                '<li><div id="' + file.id + '" class="file-item thumbnail">' +
                    '<img>' +
                    '<div class="info">' + file.name + '</div>' +
                    '<p class="progress"><span></span></p>' +
                '</div></li>'
                ),
            $img = $li.find('img');
    
    
        // $list为容器jQuery实例
    <strong>    var $list = $('#fileList');
        var thumbnailWidth = 300;
        var thumbnailHeight = 300;</strong>
        $list.append( $li );
    
        // 创建缩略图
        // 如果为非图片文件,可以不用调用此方法。
        // thumbnailWidth x thumbnailHeight 为 100 x 100
        uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
                $img.replaceWith('<span>不能预览</span>');
                return;
            }
    
            $img.attr( 'src', src );
        }, thumbnailWidth, thumbnailHeight );
    });
    // 文件上传过程中创建进度条实时显示。
    uploader.on( 'uploadProgress', function( file, percentage ) {
        var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');
    
        // 避免重复创建
        if ( !$percent.length ) {
            $percent = $('<p class="progress"><span></span></p>')
                    .appendTo( $li )
                    .find('span');
        }
    
        $percent.css( 'width', percentage * 100 + '%' );
    });
    
    // 文件上传成功,给item添加成功class, 用样式标记上传成功。
    uploader.on( 'uploadSuccess', function( file, response) {
        $( '#'+file.id ).addClass('upload-state-done');
    	console.log(response._raw);
    	// $('#pic').val(response._raw);
    
    });
    
    // 文件上传失败,显示上传出错。
    uploader.on( 'uploadError', function( file ) {
        var $li = $( '#'+file.id ),
            $error = $li.find('div.error');
    
        // 避免重复创建
        if ( !$error.length ) {
            $error = $('<div class="error"></div>').appendTo( $li );
        }
    
        $error.text('上传失败');
    });
    
    // 完成上传完了,成功或者失败,先删除进度条。
    uploader.on( 'uploadComplete', function( file ) {
        // $( '#'+file.id ).find('.progress').remove();
        // console.log(file);
    });

    点击查看

  • 最简单的图片上传

    0,先了解一下enctype

    application/x-www-form-urlencoded 在发送前编码所有字符(默认)
    multipart/form-data 不对字符编码。
    在使用包含文件上传控件的表单时,必须使用该值。
    text/plain 空格转换为 “+” 加号,但不对特殊字符编码。

    1,index.html

    <!DOCTYPE html>
    <html lang="zh-cmn-Hans">
    <head>
    	<meta charset="UTF-8">
    	<title>最简单的图片上传demo</title>
    </head>
    <body>
    	<form action="./upload.active.php" enctype="multipart/form-data" method="post">
    		<input type="file" name="file">
    		<input type="submit" value="提交">
    	</form>
    </body>
    </html>

    upload.active.php

    <?php
    $fileInfo = $_FILES['file'];
    
    echo "<pre>";
    print_r($fileInfo);
    echo "</pre>";

    立即查看

    2,php页面增加过滤(注意:文件的拥有者php-fpm或者文件夹权限777)

    <?php 
    
    $fileInfo = $_FILES['file'];
    
    $ext = pathinfo($fileInfo['name'],PATHINFO_EXTENSION);
    
    $allowExt = array('jpg','png','gif','jpeg');
    
    // 1,判断错误号
    if($fileInfo['error']>0){
    	exit('有错误');
    }
    
    // 2,是检查文件后缀
    if(!in_array($ext, $allowExt)){
    	exit('非法文件类型');
    }
    // 3,检测文件大小
    $maxSize = 10*1024*1024; //10M
    if($fileInfo['size']>$maxSize){
    	exit('上传文件过大');
    }
    
    // 4检查文件类型
    $flag = true;
    if($flag){
    	if(!getimagesize($fileInfo['tmp_name'])){
    		exit('不是图片类型');
    	}
    }
    // 5,检测是否通过http post提交
    if(!is_uploaded_file($fileInfo['tmp_name'])){
    	exit('文件不是通过HTTP POST提交');
    }
    // 6,判断是否移动成功
    // $day = 
    $uploadPath = './images';
    if(!file_exists($uploadPath)){
    	mkdir($uploadPath,0777,true);
    	chmod($uploadPath,0777);
    }
    
    // 随机一个图片的名字
    $uniName = md5(uniqid(microtime(true),true)).'.'.$ext;
    
    $destination = $uploadPath.'/'.$uniName;
    if(!@move_uploaded_file($fileInfo['tmp_name'], $destination)){
    	exit('文件移动失败');
    }
    
    echo '<a href="'.$destination.'">'.$destination.'</a>';

    立即查看

  • 判断是否Safari浏览器

    demo:https://www.dongshushu.com/issafari.html

    function issafari(){
          var ua = navigator.userAgent.toLocaleLowerCase();
    
            if(/safari/.test(ua) && !/chrome/.test(ua)){
              alert('苹果浏览器');
            }else{
              alert('非苹果浏览器');
            }
      }
  • php文件上传

    一,form表单

    <form action="upload.php" method="post" enctype="multipart/form-data">
      <label for="file">请选择你要上传的文件</label><input type="file" name="file">
      <input type="submit" value="上传">
    </form>

    二,upload.php

    <?php 
    print_r($_FILES);
    ?>

    两个函数

    copy(file,newloc)
    move_uploaded_file(file,newloc)

    三,服务器配置