【问题标题】:How to upload mp3 files如何上传mp3文件
【发布时间】:2014-05-18 13:49:17
【问题描述】:

我正在尝试获取将 mp3 或某些图像文件上传到文件夹的表单。
使用下面的代码我可以上传图像文件,但是当我尝试上传 mp3 时,我收到错误 Undefined index: file in C:\wamp\www\recordlabel\inc\soundclips.php on line 6 并且代码从我的 else 块中回显 invalid file。谁能提供帮助?

 $allowedExts = array("mp3", "jpeg", "jpg", "png");
 $temp = explode(".", $_FILES["file"]["name"]);
 $extension = end($temp);

 if ((($_FILES["file"]["type"] == "audio/mp3")
        || ($_FILES["file"]["type"] == "image/jpeg")
        || ($_FILES["file"]["type"] == "image/jpg")
        || ($_FILES["file"]["type"] == "image/pjpeg")
        || ($_FILES["file"]["type"] == "image/x-png")
        || ($_FILES["file"]["type"] == "image/png"))
        && in_array($extension, $allowedExts))
{
   if ($_FILES["file"]["error"] > 0)
   {
      echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
   }
   else
   {
      echo "Upload: " . $_FILES["file"]["name"] . "<br>";
      echo "Type: " . $_FILES["file"]["type"] . "<br>";
      echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
      echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

      if (file_exists("../soundclips/" . $_FILES["file"]["name"]))
      {
         echo $_FILES["file"]["name"] . " already exists. ";
      }
      else
      {
         move_uploaded_file($_FILES["file"]["tmp_name"],
         "../soundclips/" . $_FILES["file"]["name"]);
         echo "Stored in: " . "../soundclips/" . $_FILES["file"]["name"];
      }
   }
}
else
{
    echo "Invalid file";
}

这是我的表格

<form class='form1' action='../inc/soundclips.php' method='post'     
                                                   enctype='multipart/form-data'>
   <input type="hidden" name="id" value="<?php echo $pid; ?>"/>
   <b>Add Soundclip For <i><?php echo $e;?></i> </b> 
   <?php echo"<divclass='editimage'>";
   echo "<img class='resizedimage' src='{$row['image']}' />";
   echo"</div>";?><br /> 
   <b>Song</b><br /><input type=text size='60' name='asong' /><br />
   <input name='file' type="file" id="file"  /><br />
   <input type='submit' name='add' value='Add Soundclip' />
</form>

【问题讨论】:

    标签: php


    【解决方案1】:

    您的 mp3 文件似乎无法上传,因此 $_FILES 数组中缺少该文件。这可能是由于其与图像文件相比的大小。

    请检查php.ini 中的upload_max_filesizepost_max_size 设置,并允许大于您的mp3 文件。

    【讨论】:

    • 我刚刚这样做了,同样的事情仍然发生!
    • 您更改了这些值还是已经大于 mp3 文件大小?
    • 我把 vales 都改成了 30m
    • 你重启了你的网络服务器吗?
    • 哇!不,我没有!重新启动后它现在可以工作了。谢谢,接受您的回答。
    猜你喜欢
    • 1970-01-01
    • 2010-10-21
    • 2016-07-25
    • 2017-10-13
    • 1970-01-01
    • 2016-12-01
    • 2014-05-10
    • 2019-12-10
    • 2020-05-05
    相关资源
    最近更新 更多