ThinkPHP5中怎么利用ajax插入图片并实时显示
这篇文章给大家介绍ThinkPHP5中怎么利用ajax插入图片并实时显示,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。
目前创新互联建站已为上千的企业提供了网站建设、域名、雅安服务器托管、网站托管运营、企业网站设计、鄂城网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
完整代码:
ajax上传图片练习
tp控制器代码
public function measurement() { $response = array(); //这是身份证正面 if ( isset( $_FILES['drawing'] ) && $_FILES['drawing']['error'] == 0 ) { $drawing = request()->file('drawing'); $picture = $drawing->validate( ['ext'=>'jpg,png,gif'] )->move( ROOT_PATH . 'static' . DS . 'upload/mi/img' ); } if ( isset( $picture ) ) { $filePaths = '/static' . DS . 'upload/mi/img/'. $picture->getSaveName(); $response['whether'] = true; $response['site'] = $filePaths; echo json_encode($response); } // 正面结束 }
多个上传
展示:
完整代码:
文件上传
tp控制器中
public function measurement() { $response = array(); //这是身份证正面 if ( isset( $_FILES['drawing'] ) && $_FILES['drawing']['error'] == 0 ) { $drawing = request()->file('drawing'); $picture = $drawing->validate( ['ext'=>'jpg,png,gif'] )->move( ROOT_PATH . 'static' . DS . 'upload/mi/img' ); } if ( isset( $picture ) ) { $filePaths = '/static' . DS . 'upload/mi/img/'. $picture->getSaveName(); $response['whether'] = true; $response['site'] = $filePaths; echo json_encode($response); } // 正面结束 // 这是反面 if ( isset( $_FILES['reverse'] ) && $_FILES['reverse']['error'] == 0 ) { $reverse = request()->file('reverse'); $reverse = $reverse->validate( ['ext'=>'jpg,png,gif'] )->move( ROOT_PATH . 'static' . DS . 'upload/mi/img' ); } if ( isset( $reverse ) ) { $contrary = '/static' . DS . 'upload/mi/img/'. $reverse->getSaveName(); $response['whether'] = true; $response['site'] = $contrary; echo json_encode($response); } //银行卡正面 if ( isset( $_FILES['transaction'] ) && $_FILES['transaction']['error'] == 0 ) { $transaction = request()->file('transaction'); $transaction = $transaction->validate( ['ext'=>'jpg,png,gif'] )->move( ROOT_PATH . 'static' . DS . 'upload/mi/img' ); } if ( isset( $transaction ) ) { $stuck = '/static' . DS . 'upload/mi/img/'. $transaction->getSaveName(); $response['whether'] = true; $response['site'] = $stuck; echo json_encode($response); } //银行卡反面 if ( isset( $_FILES['redlining'] ) && $_FILES['redlining']['error'] == 0 ) { $redlining = request()->file('redlining'); $redlining = $redlining->validate( ['ext'=>'jpg,png,gif'] )->move( ROOT_PATH . 'static' . DS . 'upload/mi/img' ); } if ( isset( $redlining ) ) { $other = '/static' . DS . 'upload/mi/img/'. $redlining->getSaveName(); $response['whether'] = true; $response['site'] = $other; echo json_encode($response); } }
关于ThinkPHP5中怎么利用ajax插入图片并实时显示就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
新闻标题:ThinkPHP5中怎么利用ajax插入图片并实时显示
网站网址:http://lswzjz.com/article/jjhpch.html