0

The case statement in php here to check a mime type is working fine.

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

    case "video/mp4":
    case "video/mov":
~~~~~~~~~~~~~~~~~

However, the case statement in php here to check a file extention is not, and in this case pathinfo($path) is not extracting a filename such as VID_2_134.mp4. I guess the way I used pathinfo($path) is not correct, but I don't know the correct way to use it. If I replace pathinfo($path) with VID_2_134.mp4 below the case statement starts to work with the way I expected.

$filepath = pathinfo($path);
$extension = $filepath['extension'];
switch ($extension) {

     case "mp4":
     case "mov":
~~~~~~~~~~~~~~~~~

*$path is a file path from the local drive of pc or smartphone where the file exist.

Can anyone please help me out?

user27240
  • 49
  • 10
  • 2
    So what does `$filepath` contain? It should be an associative array Can you dump it? – arkascha Sep 20 '18 at 18:19
  • Was about to suggest `var_dump($path);` and `var_dump($filepath);` – Cid Sep 20 '18 at 18:21
  • I'm almost sure there's a special character (a newline at the end?) that prevents pathinfo() from working correctly. – dkellner Sep 20 '18 at 18:24
  • arkascha, thanks. It says array(2) { ["basename"]=> string(0) "" ["filename"]=> string(0) "" } – user27240 Sep 20 '18 at 18:25
  • Cid, string(14) "/tmp/phpoV3m9a" array(3) { ["dirname"]=> string(4) "/tmp" ["basename"]=> string(9) "phpoV3m9a" ["filename"]=> string(9) "phpoV3m9a" } – user27240 Sep 20 '18 at 18:33
  • 1
    Looks like that's a file without extension or you forgot to add the file. – Cid Sep 20 '18 at 18:36
  • I do see the extension of the file when I choose it for uploading. – user27240 Sep 20 '18 at 18:42
  • 1
    It is a temporary upload. Upload it, then get the extension when it is a standard file. – user3783243 Sep 20 '18 at 18:56
  • Thank you all. Your insights and advises helped me a lot. Since a file in $path does not contain an extension in this particular case which I did not realize I managed to check a file extension by changing the root from $path to temp folder. I really appreciate your supports. – user27240 Sep 21 '18 at 17:04

0 Answers0