gpt4 book ai didi

php - 使用PHP上传mp3时出错

转载 作者:行者123 更新时间:2023-12-03 02:28:40 25 4
gpt4 key购买 nike

我在网页上有一个表格,允许用户上传mp3文件。除非文件超过2MB,否则它的工作原理非常好。然后显示“抱歉,上传文件时出错。”我测试了2mb-6mb的mp3,它们无法正常工作,我相信我已经将代码调整为可以接受超过2MB的文件。有人可以帮忙吗?

这是HTML,(我认为这不是问题):

<div id="contactpara">
<form id="upform" action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Music" name="submit">
<iframe id="upload_target" name="upload_target" src="" style="width:500px;height:100px;border:0px solid #000;"></iframe>
</form>
</div>

这是PHP:
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 10000000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "mp3" ) {
echo "Sorry, only mp3 files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>

之所以说$ imageFileType是因为这是一个PHP代码,用于接受我调整后的图像以接收音频文件。这可能是造成问题的原因吗?请告诉我。

最佳答案

我有点同样的问题,发现它是2m的max_filesize。它使我认为我已经解决了很多问题。解决方案是将max_filesize更改为所需的数量

关于php - 使用PHP上传mp3时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28679415/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com