Question

I have this script for uploading files it uploads mp4 files but i cant get it to work for flv and avi

Html Code

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

and the php code

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

when i try uploading flv it returns an error saying the "Notice: Undefined index: files on line 16" Dont know why this occurs Any Help would be appreciated

Was it helpful?

Solution

I have a feeling you're issue is from the file your trying to upload, the tutorial you followed worked properly and it should have worked for you. Your HTML form was not updated to process this script either on your server as an FYI.

You will need to edit PHP.INI and change those two parameters:

 upload_max_filesize = 500M
 post_max_size = 500M

... for a maximum upload filesize of 500MB, to make sure the filesize is allowed by the server.

This behavior explains why the index is not found.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top