tp3后台音频的增删改查,tp3上传音乐

本文介绍了在ThinkPHP3框架中如何进行音频文件的增删改查操作,包括设置php.ini中的post_max_size和upload_max_filesize参数,以及涉及的模型、控制器和视图的实现。
摘要由CSDN通过智能技术生成

首先得注意php.ini里的 post_max_size 和 upload_max_filesize 值得设置

模型

<?php
namespace Admin\Model;
use Think\Model;
class MusicModel extends Model {



}

 

控制器

public function add(){

    $music=D('music');

    //添加操作
    if(IS_POST){
        $data['title']=I('title');
        $data['author']=I('author');
        $data['time']=time();

        if($_FILES['music']['tmp_name']!=''){
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     31457280 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg','mp3');// 设置附件上传类型
            $upload->rootPath='./';
            $upload->savePath  =      './Public/Uploads/'; // 设置附件上传目录
            $info=$upload->uploadOne($_FILES['music']);
            if(!$info) {// 上传错误提示错误信息
                $this->error($upload->getError());
            }else{// 上传成功
                $data['music']=$info['savepath'].$info['savename'];
            }
        }


        if($music->create($data)){
            if($music->add()){
                $this->success('音乐新增成功',U('lst'));
            }else{
                $this->error('音乐新增失败!');
            }
        }else{
            $this->error($music->getError());
        }
        return;
    }
    $this->display();
}

 

视图

<form method="post" action="" enctype="multipart/form-data">
   <table class="tbl" width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce" onmouseover="changeto()"  onmouseout="changeback()">
     <tr>
       <td height="20" bgcolor="#FFFFFF" class="STYLE6" align="right">音乐名</td>
       <td height="20" bgcolor="#FFFFFF" class="STYLE19" align="left"><input name="title" type="text" /></td>
</tr>
   
   <tr>
       <td height="20" bgcolor="#FFFFFF" class="STYLE6" align="right">作者</td>
       <td height="20" bgcolor="#FFFFFF" class="STYLE19" align="left"><input name="author" type="text" /></td>
</tr>

  <tr>
       <td height="20" bgcolor="#FFFFFF" class="STYLE6" align="right">音频</td>
       <td height="20" bgcolor="#FFFFFF" class="STYLE19" align="left">
           <input name="music" id="test" type="file" />
           <audio id="audio" controls autoplay="" style="display: none; "></audio>
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值