Appinventor源码

Appinventor源码

php源码

config.php

<?php

define('FILE_UPLOAD_TOKEN','123456');//上传文件密钥

define('FILE_UPLOAD_PATH','upload/');//上传文件目录

define('FILE_UPLOAD_MAXTIME','30');//上传文件超时时间单位秒

define('FILE_UPLOAD_TYPE','png,jpg,jpeg,mp4');//上传文件类型

upload.php

<?php

include('config.php');
isset($_POST['fileName'])?$upload_fileName = $_POST['fileName']:exit('缺少参数');
isset($_POST['fileBase64'])?$upload_fileBase64 = $_POST['fileBase64']:exit('缺少参数');
isset($_POST['fileType'])?$upload_fileType = $_POST['fileType']:exit('缺少参数');
isset($_POST['sign'])?$upload_sign = $_POST['sign']:exit('缺少参数');
isset($_POST['ts'])?$upload_ts = $_POST['ts']:exit('缺少参数');
//校验时间戳
$upload_ts-time()<3&&time()-$upload_ts<FILE_UPLOAD_MAXTIME?0:exit('请求超时');//根据实际情况调整
//校验签名
$upload_sign == md5($upload_fileName.$upload_fileBase64.$upload_fileType.FILE_UPLOAD_TOKEN.$upload_ts)?0:exit('签名校验失败');
//检查上传文件类型
$fileTypeArray = explode(',', strtolower(FILE_UPLOAD_TYPE));
in_array($upload_fileType,$fileTypeArray)?$fileType = $upload_fileType:exit('不支持的文件类型');
//储存文件
$fileID = uniqid('upload_');
file_exists(FILE_UPLOAD_PATH)?0:mkdir(FILE_UPLOAD_PATH);
$fileName = FILE_UPLOAD_PATH.$fileID.'.'.$fileType;
$myfile = fopen($fileName, "w") or die("Unable to open file!");
fwrite($myfile, base64_decode($upload_fileBase64));
fclose($myfile);
//获得文件URL
$protocol = ((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off') || $_SERVER['SERVER_PORT'] == 443) ?"https://": "http://";
$url = $protocol . $_SERVER['HTTP_HOST'] . "/" . pathinfo($fileName)['dirname'] . "/" . pathinfo($fileName)['basename'];
//返回信息
$time_consuming = time()-$upload_ts;
echo "文件上传成功!链接:{$url} 耗时:{$time_consuming}秒";

源码下载

php源码
Appinventor源码

最后修改:2022 年 08 月 28 日
如果觉得我的文章对你有用,请随意点赞+分享