0

With php file like below to upload video files from local drive to the application that I'm currently developping, (before being played at html, so html coding has nothing to do with it.) I can successfully upload mp4, mov, flv, and avi, but I can not upload wmv, mpg, and asf with messages saying "the mime type is not found on this list" which comes from this php file and I made this message by myself.

So, it is happening within this php file, before the browser(html file) recognizes what kind of file it is.

~~~~~~~
$mimetype = mime_content_type($path);
switch ($mimetype) {

    case "video/mp4":

    if($header){
    header("Content-Type: video/mp4");
    $dst_im = copy($path, $dst_file);
    return "";
    }else{
    $dst_file = $dst_file . ".mp4";
    if($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
    copy($path, $dst_file);
    } else {
    $dst_im = copy($path, $dst_file);
    }
    }
    unlink($dst_im);
    break;

    case "video/x-ms-wmv":

    if($header){
    header("Content-Type: video/x-ms-wmv");
    $dst_im = copy($path, $dst_file);
    return "";
    }else{
    $dst_file = $dst_file . ".wmv";
    if($re_size[0] == $size[0] && $re_size[1] == $size[1]) {
    copy($path, $dst_file);
    } else {
    $dst_im = copy($path, $dst_file);
    }
    }
    unlink($dst_im);
    break;

    case "video/quicktime":
    case "video/x-msvideo":
    case "video/x-flv":
    case "video/mpeg":
    case "video/x-ms-asf":
default:
return array(0, "* the mime type is not found on this list.");
        }
return array(1, $dst_file);
        }               
~~~~~~~


ext.  mime               result                  origin of file

mp4   video/mp4          uploaded                Shot with my smartphone
mov   video/quicktime    uploaded                Shot with my smartphone
avi   video/x-msvideo    uploaded                Shot with my camera
flv   video/x-flv        uploaded                Downloaded from web

wmv   video/x-ms-wmv     can't be uploaded       Downloaded from web
mpg   video/mpeg         can't be uploaded       Downloaded from web
asf   video/x-ms-asf     can't be uploaded       Downloaded from web

I also have made proper .htaccess setting.

I think that,

*The html coding is not issue here.

*The browser type is not issue here.

*The coding of php file is not issue here, because some are uploaded with the same php file and there're no indication of mime type and file extension other than this php file.

*The sizes of files are not issue here, because those files that I can't upload are smaller than that of mp4 file.

So I'm thinking something must be wrong with mime type that I used or video file itself, but I have no idea why it is happening.

Can anyone please help me out?

user27240
  • 49
  • 10
  • 2
    Pleassssse indent your control structures. This is almost unreadable. Run `var_dump($mimetype);` when uploading one of those files and see what you actual have. – user3783243 Sep 18 '18 at 20:48
  • user3783243, Thanks a lot. Wmv, mpg, and asf files have same mime type of "application/octet-stream". So, it is the reason why I can not upload. I need sample file of those file type to test, do you happen to know where I can get those files? – user27240 Sep 18 '18 at 21:07
  • Sorry, can't help with that. – user3783243 Sep 18 '18 at 21:12
  • user3783243, anyway, you solved the problem I have been facing for long time. I really appreciate it. – user27240 Sep 18 '18 at 21:25
  • I don't really consider what I gave you to be an answer so I'm not going to put it below. `var_dump` is a command you should get familiar with for debugging though. Note `application/octet-stream` is not exclusive to video files so I wouldn't add that to your allowed mime types. You should use a tab or 4-5 spaces at the start of every control structure e.g. `switch`, `if`, `while`, `for`, `case`, etc. and then go back the same number of tabs/spaces when closing that group. – user3783243 Sep 18 '18 at 21:36
  • user3783243, Thank you for further information. I will not use application/octet-stream and I will try to find wmv, mpg, and asf files to test whether or not they would work for my system. – user27240 Sep 18 '18 at 21:46
  • @user3783243,I start to confuse again about how to set mime type of wmv for this php file in this case. Is it video/x-ms-wmv or application/octet-stream? Is it like multiple mime type? Could you show me how I should change the php file for this case? Or should I change anything else such as server setting? – user27240 Sep 19 '18 at 14:23

0 Answers0