我在网页上有一个表单,允许用户上传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代码,用于接受我调整接受音频文件的图像。这会导致这个问题吗?请告诉我。
答案 0 :(得分:-1)
我有同样的问题,发现它是max_filesize,它是2米。它让我觉得很麻烦我解决了..解决方案只是将max_filesize更改为你想要的数量