| xqd
@@ -39,7 +39,7 @@ class FileUpload {
|
|
|
<div class="WebUploader">
|
|
|
<div class="WebUploader_button">
|
|
|
<div class="input-group">
|
|
|
- <input type="text" class="form-control input-uploadfile" value="{$file}" name="{$name}" placeholder="{$option['placeholder']}" readonly>
|
|
|
+ <input type="text" class="form-control input-uploadfile" id="pdfUpload" value="{$file}" name="{$name}" placeholder="{$option['placeholder']}" readonly>
|
|
|
<div class="input-group-btn">
|
|
|
<div id="{$id}" class="btn-xs {$option['button_class']}">上传文件</div>
|
|
|
</div>
|
| xqd
@@ -107,11 +107,129 @@ class FileUpload {
|
|
|
|
|
|
}
|
|
|
webUpload{$id}();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
</script>
|
|
|
EOF;
|
|
|
return $html;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 单个文件上传
|
|
|
+ * @param $folder
|
|
|
+ * @param string $positions
|
|
|
+ * @param array $option
|
|
|
+ */
|
|
|
+ public function singles($folder, $id, $name = "data[file]", $file = "", $id_order , $option = [], $param = [])
|
|
|
+ {
|
|
|
+ $file_types = 'jpg|jpeg|gif|png|bmp|doc|docx|xls|xlsx|ppt|htm|html|php|txt|zip|rar|gz|bz2|pdf';
|
|
|
+ $option['position'] = isset($option['position']) ? $option['position'] : "alioss";
|
|
|
+ $option['placeholder'] = isset($option['placeholder']) ? $option['placeholder'] : "";
|
|
|
+ $option['button_class'] = isset($option['button_class']) ? $option['button_class'] : "";
|
|
|
+
|
|
|
+ //扩展参数
|
|
|
+ $extParam = '';
|
|
|
+ if($param){
|
|
|
+ foreach($param AS $key => $val){
|
|
|
+ $extParam .= $key . ":" . $val . ',';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $token = csrf_token();
|
|
|
+ $html = <<<EOF
|
|
|
+ <link href="/base/webuploader/webuploader.css" rel="stylesheet">
|
|
|
+ <script src="/base/webuploader/webuploader.min.js"></script>
|
|
|
+
|
|
|
+ <input type="hidden" class="form-control input-uploadfile" value="{$file}" name="{$name}" placeholder="{$option['placeholder']}" readonly>
|
|
|
+ <button id="{$id}" class="btn btn-primary {$option['button_class']}">上传</button>
|
|
|
+
|
|
|
+
|
|
|
+ <script type="text/javascript">
|
|
|
+ function webUpload{$id}() {
|
|
|
+ var uploaderthis="#{$id}";
|
|
|
+ var uploader = WebUploader.create({
|
|
|
+ auto: true,
|
|
|
+ pick: {
|
|
|
+ id: uploaderthis,
|
|
|
+ multiple: false,
|
|
|
+ },
|
|
|
+ accept: {
|
|
|
+ title: 'Files',
|
|
|
+ extensions: "{$file_types}",
|
|
|
+ },
|
|
|
+ swf: "/base/webuploader/uploader.swf",
|
|
|
+ server: "/admin/Base/Attachment/webupload",
|
|
|
+ fileNumLimit: 300,
|
|
|
+ fileSizeLimit: 20 * 1024 * 1024,
|
|
|
+ fileSingleSizeLimit: 10 * 1024 * 1024,
|
|
|
+ });
|
|
|
+ uploader.option("formData", {
|
|
|
+ $extParam
|
|
|
+ _time: Math.random(),
|
|
|
+ _token : "{$token}",
|
|
|
+ _position : "{$option['position']}",
|
|
|
+ elementid : "",
|
|
|
+ file_type : "file",
|
|
|
+ folder : "{$folder}"
|
|
|
+ });
|
|
|
+ uploader.on("error",function(type){
|
|
|
+ if(type=='F_EXCEED_SIZE'){
|
|
|
+ layer.msg("上传的文件不大于10MB", {icon: 2});
|
|
|
+ return false;
|
|
|
+ }else if(type=="Q_TYPE_DENIED"){
|
|
|
+ layer.msg("请上传格式正确的文件", {icon: 2});
|
|
|
+ return false;
|
|
|
+ }else {
|
|
|
+ layer.msg("服务器繁忙请稍候再试", {icon: 2});
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ uploader.on("uploadProgress",function(file,percentage){
|
|
|
+ var re = /([0-9]+\.[0-9]{2})[0-9]*/;
|
|
|
+ aNew = parseFloat(percentage*100).toFixed(0);
|
|
|
+ $(uploaderthis).parent().parent().find(".webuploader-pick").html(aNew+"%");
|
|
|
+ if(percentage==1){
|
|
|
+ $(uploaderthis).parent().parent().find(".webuploader-pick").html('保存中...');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ uploader.on('uploadSuccess', function( file, response ) {
|
|
|
+ uploader.removeFile( file );
|
|
|
+ if(response.code == 200){
|
|
|
+ $(uploaderthis).parent().parent().find(".input-uploadfile").val(response.fileurl);
|
|
|
+ $(uploaderthis).parent().parent().find(".webuploader-pick").html('上传完成');
|
|
|
+ }else{
|
|
|
+ layer.msg(response.message, {icon: 2});
|
|
|
+ $(uploaderthis).parent().parent().find(".webuploader-pick").html('上传失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ }
|
|
|
+ webUpload{$id}();
|
|
|
+
|
|
|
+ $.ajax({
|
|
|
+ url:"{{ url('/web/Index/sms') }}",
|
|
|
+ traditional:true,
|
|
|
+ headers: {
|
|
|
+ 'X-CSRF-TOKEN': "{{ csrf_token() }}"
|
|
|
+ },
|
|
|
+ type:'POST',
|
|
|
+ data:{
|
|
|
+ url:$('#pdfUpload').val(),
|
|
|
+ id:{$id_order}
|
|
|
+ },
|
|
|
+ success:function (msg) {
|
|
|
+ if(msg.state ==0){
|
|
|
+ alert("上传失败!")
|
|
|
+ } else if(msg.state ==1){
|
|
|
+ alert('上传成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+EOF;
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
|
|
|
public function single2($folder, $id, $name="data", $file="", $option=[]){
|
|
|
$folder = urlencode($folder);
|