简体   繁体   English

上载mp4档案

[英]Upload mp4 file

I'm trying to upload a mp4 file with php, and I succeed it, but after that, the file can't be run with VLC, even though it could be run before upload. 我正在尝试使用php上传mp4文件,但我成功了,但是之后,该文件无法与VLC一起运行,即使它可以在上传之前运行。 The error message says that the file can't be opened gives me the path of the file and ends with (Bad File Descriptor). 错误消息指出文件无法打开为我提供了文件路径,并以(Bad File Descriptor)结尾。 I've made the following configurations in php.ini file: 我在php.ini文件中进行了以下配置:

file_uploads = On
upload_max_filesize = 25M
post_max_size = 25M

Here is my code: 这是我的代码:

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>

You had a syntax error on line 4 & 5. It should be 您在第4行和第5行有语法错误。应该是

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

Not: 不:

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

This code has been tested and is working. 此代码已经过测试,正在运行。

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM