uploadify插件单图片上传

来源:互联网 发布:淘宝正品商城在哪 编辑:程序博客网 时间:2024/06/11 09:29
Route::any('upload', 'CommonController@upload');
//////////////////////////////////////////////////////////////////////////////////////////////
<link rel="stylesheet" type="text/css" href="{{asset('resources/org/uploadify/uploadify.css')}}">
<style>
.uploadify{display:inline-block;}
.uploadify-button{border:none; border-radius:5px; margin-top:8px;}
table.add_tab tr td span.uploadify-button-text{color: #FFF; margin:0;}
</style>

    <input type="text" size="50" name="art_thumb">
    <input id="file_upload" name="file_upload" type="file" multiple="true">
    <img src="" alt="" id="art_thumb_img" style="max-width: 350px; max-height:100px;">

  <script src="{{asset('resources/org/uploadify/jquery.uploadify.min.js')}}" type="text/javascript"></script>
     <script type="text/javascript">
                            <?php $timestamp = time();?>
                            $(function() {
                                $('#file_upload').uploadify({
                                    'buttonText' : '图片上传',//按钮子
                                    'formData'     : {
                                        'timestamp' : '<?php echo $timestamp;?>',
                                        '_token'     : "{{csrf_token()}}" //头肯
                                    },
                                    'swf'      : "{{asset('resources/org/uploadify/uploadify.swf')}}",
                                    'uploader' : "{{url('admin/upload')}}",  //上传的路径
                                    'onUploadSuccess' : function(file, data, response) {
                                        $('input[name=art_thumb]').val(data);
                                        $('#art_thumb_img').attr('src','/'+data);
//                                    alert(data);
                                    }
                                });
                            });
       </script>

// //图片上传
public function upload()
{
    $file = Input::file('Filedata');//获取文件信息
    if($file -> isValid()){
        //$realPath = $file -> getRealPath(); //临时文件的绝对路径.
        $entension = $file -> getClientOriginalExtension(); //上传文件的后缀.
        $newName = date('YmdHis').mt_rand(100,999).'.'.$entension;
        $path = $file -> move(base_path().'/public/uploads',$newName);
        //////////////////////文件根目录
        $filepath = 'uploads/'.$newName;
        return $filepath;
    }
}

<td><img src="{{asset($v->imgpath)}}" style="width:200px;height:60px;"></td>


0 0