flv视频没有上传

时间:2014-04-16 17:44:31

标签: php html upload

我有这个脚本用于上传上传mp4文件的文件,但我不能让它适用于flv和avi

Html代码

<div class="wrap">
        <h1><a href="http://www.w3bees.com/2013/02/multiple-file-upload-with-php.html">Multiple File Upload with PHP</a></h1>
        <?php
        # error messages
        if (isset($message)) {
            foreach ($message as $msg) {
                printf("<p class='status'>%s</p></ br>\n", $msg);
            }
        }
        # success message
        if($count !=0){
            printf("<p class='status'>%d files added successfully!</p>\n", $count);
        }
        ?>
        <p>Max file size 100000kb, Valid formats jpg, png, gif</p>
        <br />
        <br />
        <!-- Multiple file upload html form-->
        <form action="" method="post" enctype="multipart/form-data">
            <input type="file" name="files[]" multiple="multiple">
            <input type="submit" value="Upload">
        </form>
</div>

和php代码

$valid_formats = array("mp4", "flv", "avi");
$valid_formats = array_map('strtolower', $valid_formats);
$max_file_size = 1024*1000000; //100 kb
$path = "uploads/"; // Upload directory
$count = 0;

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
    // Loop $_FILES to execute all files
    foreach ($_FILES['files']['name'] as $f => $name) {     
        if ($_FILES['files']['error'][$f] == 4) {
            continue; // Skip file if any error found
        }          
        if ($_FILES['files']['error'][$f] == 0) {              
            if ($_FILES['files']['size'][$f] > $max_file_size) {
                $message[] = "$name is too large!.";
                continue; // Skip large files
            }
            elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $valid_formats) ){
                $message[] = "$name is not a valid format";
                continue; // Skip invalid file formats
            }
            else{ // No error found! Move uploaded files 
                if(move_uploaded_file($_FILES["files"]["tmp_name"][$f], $path.$name)) {
                    $count++; // Number of successfully uploaded files
                }
            }
        }
    }
}
?>

当我尝试上传flv时,它返回一个错误,上面写着“通知:未定义的索引:第16行的文件”不知道为什么会出现这种情况任何帮助都将不胜感激

1 个答案:

答案 0 :(得分:0)

我觉得你的问题来自你试图上传的文件,你所遵循的教程正常工作,它应该适合你。您的HTML表单未更新为在您的服务器上作为FYI处理此脚本。

您需要编辑PHP.INI并更改这两个参数:

 upload_max_filesize = 500M
 post_max_size = 500M

...最大上传文件大小为500MB,以确保服务器允许文件大小。

此行为解释了找不到索引的原因。