用于上传mp3文件的php脚本不会播放球

时间:2010-09-29 19:15:30

标签: php file-upload mp3

在谷歌上看了一段时间后,我被困了= /有人可以帮帮我吗?

似乎可以使用我尝试的大多数文件,除了.mp3文件。

(X)HTML

<html>
<body>
  <form enctype="multipart/form-data" action="upload.php" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="71680000" />
    Choose a file to upload: <input name="uploaded_file" type="file" />
    <input type="submit" value="Upload" />
  </form>
</body>
</html>

PHP

<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check file extension and size
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "mp3") && ($_FILES["uploaded_file"]["type"] == "audio/mpeg") && 
    ($_FILES["uploaded_file"]["size"] < 71680000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/up/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .mp3 files under are accepted for upload";
  }
} else {
 echo "Error: No file uploaded";
}
?>

编辑:这是var_dump的输出($ _ FILES);

array(1) {
  ["uploaded_file"]=>
  array(5) {
    ["name"]=>
    string(17) "03-AsWeTravel.mp3"
    ["type"]=>
    string(0) ""
    ["tmp_name"]=>
    string(0) ""
    ["error"]=>
    int(1)
    ["size"]=>
    int(0)
  }
}

2 个答案:

答案 0 :(得分:0)

来自http://www.php.net/manual/en/features.file-upload.errors.php

UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.

您如何处理表单中的max_file_size?

尝试更改

upload_max_filesize = 70M

或者你的php.ini中的最大大小。

答案 1 :(得分:0)

你能掌控主人吗?是不是简单地阻止了mp3?

我之前在主要ISP的免费网络托管计划上看过它......