上传mp4文件

时间:2014-12-20 09:41:13

标签: php upload mp4

我正在尝试使用php上传一个mp4文件,然后我成功了,但之后,该文件无法与VLC一起运行,即使它可以在上传之前运行。错误消息说无法打开文件给我文件的路径并以(错误的文件描述符)结束。 我在php.ini文件中进行了以下配置:

file_uploads = On
upload_max_filesize = 25M
post_max_size = 25M

这是我的代码:

if ($_FILES["video"]["name"] == "") {
     $error = "No video imported.";
  }
  else {
     if (file_exists("uploads/" . $_FILES["video"]["name"])) {
        $error = "The file already exists.";
     }
     else if ($_FILES["video"]["type"] != "video/mp4") {
        $error = "File format not supported.";
     }
     else if ($_FILES["video"]["size"] > 26214400) {
        $error = "Only files <= 25ΜΒ.";
     }
     else {
        move_uploaded_file($_FILES["video"]["tmp_name"], "uploads/" . $_FILES["video"]["name"]);
     }
  }

<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
   <fieldset>
      <div class="area">
         <label for="path">Select file:</label>
            <input class="upload" type="file" name="video"></input>
            <span><?php echo $error; ?></span><br />
      </div>
   </fieldset>

   <input type="submit" name="insert" value="upload"></input>
</form>

1 个答案:

答案 0 :(得分:2)

第4行和第4行出现语法错误它应该是

} elseif (file_exists("uploads/" . $_FILES["video"]["name"])) {

} else {
     if (file_exists("uploads/" . $_FILES["video"]["name"])) {

此代码已经过测试并正在运行。

<?php
if ($_FILES["video"]["name"] == "") {
    $error = "No video imported.";
} elseif (file_exists("uploads/" . $_FILES["video"]["name"])) {
    $error = "The file already exists.";
} elseif ($_FILES["video"]["type"] != "video/mp4") {
    $error = "File format not supported.";
} elseif ($_FILES["video"]["size"] > 26214400) {
    $error = "Only files <= 25??.";
} else {
    move_uploaded_file($_FILES["video"]["tmp_name"], "uploads/" . $_FILES["video"]["name"]);
}

?>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" enctype="multipart/form-data">
   <fieldset>
      <div class="area">
         <label for="path">Select file:</label>
            <input class="upload" type="file" name="video"></input>
            <span><?php echo $error; ?></span><br />
      </div>
   </fieldset>

   <input type="submit" name="insert" value="upload"></input>
</form>