用户如何将视频上传到我的网站?

时间:2015-07-17 11:53:31

标签: php youtube

我正在网站上工作,我希望用户上传图片或视频。

<form enctype="multipart/form-data" action="upload.php" method="post">

    <div id="filediv">
        <input name="file[]" type="file" id="file"/>
    </div>

    <br/>

    <input type="button" id="add_more" class="upload"  value="Add More Files"/>
    <input type="submit" value="Upload File" name="submit" id="upload" class="upload"/>
</form>

我的upload.php确实将图片值存储在数据库中,就像我必须这样做来存储视频一样

uplaod.php

<?php
include "dbConfig.php";
if (isset($_POST['submit']))
{
    $j = 0; 

    $name = $_FILES['file']['name'];

    $target_path = "uploads/"; 

    for ($i = 0; $i < count($_FILES['file']['name']); $i++) 
    {

        $validextensions = array("jpeg", "jpg", "png", "mp3", "mp4", "wma");  
        $ext = explode('.', basename($_FILES['file']['name'][$i]));
        $file_extension = end($ext); 

        //print_r(basename($_FILES['file']['name'][$i]));
        $target_path = $target_path . md5(uniqid()) . "." . $ext[count($ext) - 1];
        $j = $j + 1;

        if (($_FILES["file"]["size"][$i] < 1024*1024*1024)   && in_array($file_extension, $validextensions)) 
        {
            if (move_uploaded_file($_FILES['file']['tmp_name'][$i], $target_path)) 
            {
                echo $j. ').<span id="noerror">Image uploaded successfully!.</span><br/><br/>';
                $actual_image_name=$_FILES['file']['name'][$i];
                mysqli_query($link,"INSERT INTO members(avatar) VALUES ('$actual_image_name')");

            }
            else 
            {
                echo $j. ').<span id="error">please try again!.</span><br/><br/>';
            }
        } 
        else 
        {
            echo $j. ').<span id="error">***Invalid file Size or Type***</span><br/><br/>';
        }
    }
}
?>

这适用于上传图片,但不适用于上传视频。

2 个答案:

答案 0 :(得分:0)

默认情况下,maximum upload_limit设置为2 MB。因此,如果您尝试上传任何大小超过2 MB的文件,它将会失败。

要进行更改,请修改php.ini并设置

upload_max_filesize = 40M ; you may set it according to your need

答案 1 :(得分:0)

PHP has several configuration options to limit resources consumed by scripts. By default, PHP is set to allow uploads of files with a size of 2MB or less.

Try increasing the following values in php.ini, for example:

memory_limit = 32M
upload_max_filesize = 24M
post_max_size = 32M

If the upload_max_filesize is larger than post_max_size, you must increase post_max_size so that it is bigger than upload_max_size.

If the value of post_max_size is larger than memory_limit, you must increase memory_limit so that it is larger than post_max_size.

There are multiple ways to edit php.ini

希望对您有帮助