【问题标题】:Unable to upload mp3 file无法上传 mp3 文件
【发布时间】:2016-07-25 11:50:12
【问题描述】:

我已经更改了设置 max_size = 256M 的 php.in 配置,但它仍然不允许我上传。我不知道我哪里出错了.....我可以上传图片文件、pdf文件、文档文件,但不能上传mp3。 php.in 设置对我不起作用...请任何人都可以指导我。下面是我的php代码

提前致谢!

<?php
    //Concept of file upload
    if(isset($_POST['submit']))
    {

     $file = $_FILES['files']['name'];
     $type = $_FILES['files']['type'];
     $file_tmp = $_FILES['files']['tmp_name'];
     $size = $_FILES['files']['size'];
     $file_err = $_FILES['files']['error'];
    if($size!=null)
    {

        if($_FILES['files']['size'] <= 10000000   && $_FILES['files']['type'] == "audio/mpeg")
        {
     $path = "D:/";
     $path = $path.basename($file);

        if(!is_uploaded_file($file))
        {
        $flag = move_uploaded_file($file_tmp, $path);
        if($flag == true)
        {
            echo "Moved Success";
        }
        else
        {
            echo "Some problem";
        }
        }
        else
        {
            echo "Already Uploaded";
        }
      }
      else
      {
         echo "Not audio file";
      } 
    }
    else if($size > 10000000)
    {
        echo "Size exceeded";
    }

    else if($size == null)
    {
       echo "Please select a file";
    }
    else
    {
        echo "Error".$file_err;
    }

    }
    ?>
    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
    </head>
    <body>
    <form action="basic.php" method="post" enctype="multipart/form-data">
    <input type="file" name="files"/>
    <input type="submit" value="upload" name="submit"/>
    </form>
    </body>
    </html>

【问题讨论】:

  • Which mime type should I use for mp3 Mime 类型可能重复可能取决于您的浏览器。
  • 比检查大小$_FILES['files']['size']
  • 我检查文件大小@devpro 它不只接收文件...一旦我设置提交它就显示没有选择文件

标签: php html


【解决方案1】:

如果您尝试上传 mp3 文件,则 $_FILES 的类型必须是

&& $_FILES["file"]["type"] == "audio/mp3"

不是

&& $_FILES['files']['type'] == "audio/mpeg"

【讨论】:

  • 在你的情况下,你正在验证 $_FILES['files']['type'] == "audio/mpeg" 但是如果你真的想知道是否有 mp3 上传,你有验证它。查看我的更改并更改 $_FILES['files']['type'] == "audio/mpeg" for $_FILES['files']['type'] == "audio/mp3"
猜你喜欢
  • 1970-01-01
  • 2019-09-17
  • 1970-01-01
  • 2010-10-21
  • 2014-05-18
  • 2017-10-13
  • 2016-12-01
  • 2014-05-10
  • 1970-01-01
相关资源
最近更新 更多