简体   繁体   中英

Upload a video file in apache server using php

I am trying to upload a video file using php. The User will get a page where he will get an option to upload a file and then, it will get uploaded to the server. My script works fine for the jpg and png. But its not working for mp4. It does not give any error.

<?php
if(isset($_FILES['image'])){
  $errors= array();
  $file_name = $_FILES['image']['name'];
  $file_size =$_FILES['image']['size'];
  $file_tmp =$_FILES['image']['tmp_name'];
  $file_type=$_FILES['image']['type'];
  $file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

  $expensions= array("jpeg","jpg","png","mp4");

  if(in_array($file_ext,$expensions)=== false){
     $errors[]="extension not allowed, please choose a JPEG or PNG file.";
  }

  if($file_size > 20971520000000  ){
     $errors[]='File size must be excately 2 MB';
    }

  if(empty($errors)==true){
     move_uploaded_file($file_tmp,"/Library/www/yes/".$file_name);
     echo "Success";
  }
  else{
     print_r($errors);
  }
   }
?>
<html>
   <body>
  <form action="" method="POST" enctype="multipart/form-data">
     <input type="file" name="image" />
     <input type="submit"/>
     <ul>
        <li>Sent file: <?php echo $_FILES['image']['name'];  ?>
        <li>File size: <?php echo $_FILES['image']['size'];  ?>
        <li>File type: <?php echo $_FILES['image']['type'] ?>
     </ul>
  </form>
   </body>
  </html>

如果尚未在php.ini中设置/更改upload_max_filesize,则默认设置(2mb)禁止上传大于2mb的文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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