AbyssalSwamp  ActivaUser
» Guest:  Register | Login | 会员列表

RSS subscription to this AbyssalSwamp  

Previous thread Next thread
 12  1/2  1  2  > 
       
Title: 啊全,请帮我看看以下程序。  
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
啊全,请帮我看看以下程序。

我在开发以个AJAX上传语音的php程序。 程序1、 上传前端页面 代码如下: Recorder H5 QuickStart: 快速入门
Recorder H5 QuickStart: 快速入门 GitHub | Gitee
2022-11-21 17:00#1
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
以上代码录音是没有问题,接收上传的页面代码如下: 0) { echo "错误:: " . $_FILES["upfile"]["error"] . "
"; } else { echo "上传文件名: " . $_FILES["upfile"]["name"] . "
"; echo "文件类型: " . $_FILES["upfile"]["type"] . "
"; echo "文件大小: " . ($_FILES["upfile"]["size"] / 1024) . " kB
"; echo "文件临时存储的位置: " . $_FILES["upfile"]["tmp_name"] . "
"; // 判断当期目录下的 upload 目录是否存在该文件 // 如果没有 upload 目录,你需要创建它,upload 目录权限为 777 if (file_exists("upload/" . $_FILES["upfile"]["name"])) { echo $_FILES["upfile"]["name"] . " 文件已经存在。 "; } else { // 如果 upload 目录不存在该文件则将文件上传到 upload 目录下 move_uploaded_file($_FILES["upfile"]["tmp_name"], "upload/" . $_FILES["upfile"]["name"]); echo "文件存储在: " . "upload/" . $_FILES["upfile"]["name"]; } } } else { echo "非法的文件格式"; } ?>
2022-11-21 17:00#2
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
但我的代码上传不成功,所以想请你帮我看看那里写错了?
2022-11-21 17:01#3
View profile  Blog  Send a short message  Top
 
chnzbq
妙语书生



UID 181233
Digest 0
Points 7
Posts 1723
码币MB 2582 Code
黄金 731 Catty
钻石 85 Pellet
Permissions 10
Register 2019-5-3
Status offline
if ((($_FILES["upfile"]["type"] == "image/gif") || ($_FILES["upfile"]["type"] == "image/jpeg") || ($_FILES["upfile"]["type"] == "image/jpg") || ($_FILES["upfile"]["type"] == "image/pjpeg") || ($_FILES["upfile"]["type"] == "image/x-png") || ($_FILES["upfile"]["type"] == "audio/mpeg") || ($_FILES["upfile"]["type"] == "image/png")) 这段是什么东西?
2022-11-21 17:03#4
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
整套程序的源代码

Att: Recorder-master.zip (2022-11-21 17:03, 5.06 M)
Number of times this attachment has been downloaded 60
2022-11-21 17:03#5
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline


QUOTE:
原帖由 chnzbq 于 2022-11-21 17:03 发表 if ((($_FILES == "image/gif") || ($_FILES == "image/jpeg") || ($_FILES == "image/jpg") || ($_FILES == "image/pjpeg") || ($_FILES == "image/x-png&quo ...
这是一个例子,用于甄别上传文件的类型。 我在这里copy的 https://www.runoob.com/php/php-file-upload.html
2022-11-21 17:04#6
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
你帮我改改,我想能上传成功。
2022-11-21 17:04#7
View profile  Blog  Send a short message  Top
 
chnzbq
妙语书生



UID 181233
Digest 0
Points 7
Posts 1723
码币MB 2582 Code
黄金 731 Catty
钻石 85 Pellet
Permissions 10
Register 2019-5-3
Status offline
/***方式一:将blob文件转成base64纯文本编码,使用普通application/x-www-form-urlencoded表单上传***/ var reader=new FileReader(); reader.onloadend=function(){ var postData=""; postData+="mime="+encodeURIComponent(blob.type);//告诉后端,这个录音是什么格式的,可能前后端都固定的mp3可以不用写 postData+="&upfile_b64="+encodeURIComponent((/.+;\s*base64\s*,\s*(.+)$/i.exec(reader.result)||[])[1]) //录音文件内容,后端进行base64解码成二进制 //...其他表单参数 var xhr=new XMLHttpRequest(); xhr.open("POST", api); xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xhr.onreadystatechange=onreadystatechange("上传方式一【Base64】"); xhr.send(postData); }; reader.readAsDataURL(blob); /***方式二:使用FormData用multipart/form-data表单上传文件***/ var form=new FormData(); form.append("upfile",blob,"recorder.mp3"); //和普通form表单并无二致,后端接收到upfile参数的文件,文件名为recorder.mp3 //...其他表单参数 var xhr=new XMLHttpRequest(); xhr.open("POST", api); xhr.onreadystatechange=onreadystatechange("上传方式二【FormData】"); xhr.send(form); 这几段代码 可能 存在问题
2022-11-21 17:07#8
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline


QUOTE:
原帖由 chnzbq 于 2022-11-21 17:07 发表 /***方式一:将blob文件转成base64纯文本编码,使用普通application/x-www-form-urlencoded表单上传***/ var reader=new FileReader(); reader.onloadend=function(){ ...
你能修改一下吗 我想用方法2上传。 如果难就算了,我重新找个例子。
2022-11-21 17:08#9
View profile  Blog  Send a short message  Top
 
sky999
天山茗客



UID 181291
Digest 2
Points 10
Posts 3916
码币MB 2577 Code
黄金 0 Catty
钻石 884 Pellet
Permissions 10
Register 2020-11-28
Status offline
啊全,这个让我处理吧。我找到方式了
2022-11-21 17:10#10
View profile  Blog  Send a short message  Top
 12  1/2  1  2  > 
       


  Printable version | Recommend to a friend | Subscribe to topic | Favorite topic  


 


All times are GMT+8, and the current time is 2026-1-12 04:58 Clear informations ->sessions/cookies - Contact Us - CAFFZ - ZAKE