使用php上传视频文件

时间:2017-11-07 12:17:13

标签: php

我正在尝试使用php上传文件,我得到的错误表单不提交,只要一切顺利,根据我下面是代码视频上传表单

 <form action="tek.php" method="POST" enctype="multipart/form-data">
        <input type="text" name="name" placeholder="Name"><br/>
            <input type="text" name="mobile" placeholder="Mobile No."><br/>
            <input type="file" name="videouser" ><br/>
            <input type="file" name="audiouser" ><br/>
            <input type="submit" name="submit" value="Submit">
 </form>

以下是我的

tek.php
网页代码

    if(isset($_POST["submit"])){
    $name = $_POST["name"];
    $mobile = $_POST["mobile"];

    $video_dir = "admin/video/";
    $temp = explode(".", $_FILES["videouser"]["name"]);
    $newfilename = round(microtime(true)) . '.' . end($temp);
    move_uploaded_file($_FILES["videouser"]["tmp_name"], "/admin/video/" .$newfilename)or die("not uploading a video");

    $videofile = rand() . basename($_FILES["videouser"]["name"]);
    if(move_uploaded_file($_FILES["videouser"]["name"], $video_dir.$newfilename))
    {
        echo "upload video successfull";    
    }else{
        echo "video file not uploaded";
    }
    $audio_dir = "admin/audio/";
    $audiofile = rand() . basename($_FILES["audiouser"]["name"]);
    if(move_uploaded_file($_FILES["audiouser"]["name"], $audio_dir.$audiofile) or die("Not Uploaded audio"))
    {
        echo "upload audio successfull";
    }else{
        echo "audio file not uploaded"; 
    }

  }else{
    echo "form not submitted.";
  }

上面的tek.php页面代码可以正常工作但不适用于视频或音频文件我也增加限制post_max_size = 500M和upload_max_size = 500M我犯了错误不知道请提前帮助谢谢。

2 个答案:

答案 0 :(得分:0)

更改以下代码:

if(move_uploaded_file($_FILES["videouser"]["tmp_name"], $video_dir.$newfilename))
{
    echo "upload video successfull";    
}else{
    echo "video file not uploaded";
}
$audio_dir = "admin/audio/";
$audiofile = rand() . basename($_FILES["audiouser"]["name"]);
if(move_uploaded_file($_FILES["audiouser"]["tmp_name"], $audio_dir.$audiofile) or die("Not Uploaded audio"))
{
    echo "upload audio successfull";
}else{
    echo "audio file not uploaded"; 
}

你应该在移动过程中使用tmp_name而不是name

答案 1 :(得分:0)

Hi Friends i got the answer
1. first configure your php.ini 
2. if you use wamp then you get php.ini in wamp/bin/php/php7.0.10(php version)/php.ini
3. set in php.ini 
 post_max_size = 10240M 
 upload_max_filesize = 500M
4. Restart Your wamp server(must)
now the code to upload video below in upload.php
<?php
        if(isset($_FILES['file'])){
        $errors= array();
        $file_name = $_FILES['file']['name'];
        $file_size =$_FILES['file']['size'];
        $file_tmp =$_FILES['file']['tmp_name'];
        $file_type =$_FILES['file']['type'];
        if (!file_exists('uploaded_here')) { // file will be uploaded in this folder
        mkdir('uploaded_here', 0777, true);
        }
        if(empty($errors)==true){
        move_uploaded_file($file_tmp,"uploaded_here/".$file_name);
        echo "Uploaded in folder uploaded_here file name is : ".$file_name;
        }else{
        echo "Not Uploaded";
        }
        }
        ?>

        <form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" method="post" enctype="multipart/form-data">
        <input type="file" name="file" accept="file_extension|audio/*|video/*|image/*|media_type">
        <br>
        <input type="submit" value="Upload">
        </form>

为我工作