数据库怎么存放MP3文件,我之前上网搜了一下说是要先将MP3文件上传到服务器上,通过临时文件来操作,现在这些都做完了,怎么与数据库连接,又怎么显示到我的页面中呢下面是我的上传代码1.<!DOCTYPE HTML><html> <head> <meta charset="utf-8" /> <title>Music</title> </head> <body> <form action="doAction.php" method="post" enctype="multipart/form-data"> <input type="file" name="myFile"/></br> <input type="submit" value="上传文件"/> </form> </body></html>2. <?php header('content-type:text/html;charset=utf-8'); $fileInfo=$_FILES['myFile']; $filename=$fileInfo['name']; $type=$fileInfo['type']; $tmp_name=$fileInfo['tmp_name']; $size=$fileInfo['size']; $error=$fileInfo['error']; $maxSize=99999999; $allowExt=array('jpg','jpeg','mp3'); if ($error==UPLOAD_ERR_OK) { if ($fileInfo['size']>$maxSize) { exit('文件过大'); } $ext=pathinfo($fileInfo['name'],PATHINFO_EXTENSION); if(!in_array($ext, $allowExt)){ exit('非法文件类型'); } if (!is_uploaded_file($fileInfo['tmp_name'])) { exit('文件不是通过HTTP POST方式上传来的'); } $path='uploads'; //防止重名覆盖 $uniName=md5(uniqid(microtime(true),true)).'.'.$ext; //echo $uniName;exit; $destination=$path.'/'.$uniName; if (move_uploaded_file($fileInfo['tmp_name'],$destination)) { echo '文件上传成功'; }else{ echo '文件上传失败 '; } }else{ switch ($error) { case 1: echo "上传文件超过了php配置文件中upload_max_filesize选项的值"; break; case 2: echo "超过了表单MAX_FILE_SIZE限制的大小"; break; case 3: echo "文件部分被上传"; break; case 4: echo "没有选择上传文件"; break; case 6: echo "没有找到临时目录"; break; case 7: case 8: echo "系统错误"; break; } }?>
- 2 回答
- 0 关注
- 1773 浏览
添加回答
举报
0/150
提交
取消