一,配置react环境
$npm install -g create-react-app
$create-react-app 你的项目名
$npm install -g create-react-app
$create-react-app 你的项目名
<?php
function random($num){
$str = 'abcdefghijklmnopqrstuvwxyz0123456789';
$code = '';
for ($i=0; $i < $num ; $i++) {
// 随机位置
$j = rand(0,strlen($str)-1);
// 拼接字符串
$code .= substr($str, $j, 1);
}
return $code;
}
echo random(32);
npm install -g pm2
在服务器目录创建/ect/nginx/conf.d/xxxx.conf
server {
listen 80;
server_name koa.dongshushu.com(换成自己的域名);
location / {
proxy_pass http://localhost:3000(换端口);
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
重启nginx
nginx -s reload
pm2 start app
常用的pm2命令
$ pm2 list
$ pm2 stop <app_name|id|'all'|json_conf>
$ pm2 restart <app_name|id|'all'|json_conf>
$ pm2 delete <app_name|id|'all'|json_conf>
pm2升级
pm2 update
<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相当于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 中设置该项
}
一,引入文件
<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>';