Javascript 如何使用php将所有类型的音频文件上载到文件夹
我有这个网络程序,我上传两种类型的文件,一种是图像格式,另一种是音频格式,图像文件上传完美,任何类型的图像都可以工作,但有些音频文件没有上传,它不像一种特定类型的文件,例如wav没有上传,只是一些mp3文件会上传,而其他mp3文件不会 这是表格Javascript 如何使用php将所有类型的音频文件上载到文件夹,javascript,php,html,Javascript,Php,Html,我有这个网络程序,我上传两种类型的文件,一种是图像格式,另一种是音频格式,图像文件上传完美,任何类型的图像都可以工作,但有些音频文件没有上传,它不像一种特定类型的文件,例如wav没有上传,只是一些mp3文件会上传,而其他mp3文件不会 这是表格 <form method="post" enctype="multipart/form-data"> <input type="text" id="bname" placeholder="name"><br&
<form method="post" enctype="multipart/form-data">
<input type="text" id="bname" placeholder="name"><br><br>
<input type="text" id="bprice" placeholder="price"><br><br>
<label>artwork</label><input type="file" id="bartwork" placeholder="artwork" accept="image/*">
<br><br>
<label>beat</label><input type="file" id="bbeat" placeholder="beat" accept="audio/*"><br><br>
<input type="submit" id="beats" value="Upload">
</form>
这里是php
include('connect.php');
$name = $_POST['name'];
$price = $_POST['price'];
$file= $_FILES['beat'];
$filename = $_FILES['beat']['name'];
$filetmp = $_FILES['beat']['tmp_name'];
$filesize = $_FILES['beat']['size'];
$fileerror = $_FILES['beat']['error'];
$filetype = $_FILES['beat']['type'];
$fileext = explode('.',$filename);
$fileAcualext = preg_replace( "/\r|\n/", "", strtolower(end($fileext)));
if($fileerror === 0)
{
if($filesize <10000000)
{
echo $fileAcualext;
$filenamenew = $name.".".$fileAcualext;
$fiedestination = '../beats/'.$filenamenew;
move_uploaded_file($filetmp,$fiedestination);
}
else{
echo "File to big ";
}
$paco = 0;
}
else{
$paco = 1;
echo "There was an error ". $fileerror;
}
$file2= $_FILES['artwork'];
$file2name = $_FILES['artwork']['name'];
$file2tmp = $_FILES['artwork']['tmp_name'];
$file2size = $_FILES['artwork']['size'];
$file2error = $_FILES['artwork']['error'];
$file2type = $_FILES['artwork']['type'];
print_r($file);
$file2ext = explode('.',$file2name);
$file2Acualext = preg_replace( "/\r|\n/", "", strtolower(end($file2ext)));
if($file2error === 0)
{
if($file2size <10000000)
{
$filenamenew2 = $name.".".$file2Acualext;
$fiedestination2 = '../beatsartwork/'.$filenamenew2;
move_uploaded_file($file2tmp,$fiedestination2);
}
else{
echo "File to big ";
}
$paco = 0;
}
else{
$paco = 1;
echo "There was an error ";
}
if($paco == 1)
{
echo 'we could not upload ur stupid file fuck of bicth';
}
else{
$query ="INSERT INTO `beats`(`name`, `price`, `artwork`, `beat`) VALUES ('$name','$price','../beatsartwork/$filenamenew2','../beats/$filenamenew')";
$selectt = mysqli_query($conn,$query);
if(mysqli_affected_rows($conn)>0){
// header("Location:login.php");
echo 1;
}
else{
echo 0;
}
}
我不知道是什么问题,
感谢您提前提供帮助您的上传响应中出现错误[error]=>1 这是因为您选择了一个文件,该文件的大小大于您的post_max_size或upload_max_filesize 将这些值从php.ini增加到适当的值,然后在计算机中重新启动web服务器和php 上载文件时可用于检测错误的常量列表
define ('UPLOAD_ERR_OK', 0);
define ('UPLOAD_ERR_INI_SIZE', 1);
define ('UPLOAD_ERR_FORM_SIZE', 2);
define ('UPLOAD_ERR_PARTIAL', 3);
define ('UPLOAD_ERR_NO_FILE', 4);
define ('UPLOAD_ERR_NO_TMP_DIR', 6);
define ('UPLOAD_ERR_CANT_WRITE', 7);
define ('UPLOAD_ERR_EXTENSION', 8);
Array
(
[name] => Burna Boy – Anybody.mp3
[type] =>
[tmp_name] =>
[error] => 1
[size] => 0
)
define ('UPLOAD_ERR_OK', 0);
define ('UPLOAD_ERR_INI_SIZE', 1);
define ('UPLOAD_ERR_FORM_SIZE', 2);
define ('UPLOAD_ERR_PARTIAL', 3);
define ('UPLOAD_ERR_NO_FILE', 4);
define ('UPLOAD_ERR_NO_TMP_DIR', 6);
define ('UPLOAD_ERR_CANT_WRITE', 7);
define ('UPLOAD_ERR_EXTENSION', 8);