我需要将视频文件扩展名更改为mp4 [关闭]

I'd really appreciate someone doing this and also explaining what they did so I can understand it better.

Current Code:

            $name = $_FILES['file']['name'];
            $extension = strtolower(substr ($name, strpos($name, '.') + 1));
            $newextension = 'mp4';
            $type = $_FILES['file']['type'];

            $temp = $_FILES['file']['tmp_name'];

            $location = 'thelocation';

            if ($extension!==$newextension)
            {

            $extension = $newextension;

And if this can not be done, can someone inform me of a method on how to convert all none .mp4 files into .mp4 files serverside and if it is a automatic method or will have to be done manually.

Remember that you're working with a temporary file, that needs to be copied from your temp directory to a final location such as /videos/video.mp4.

So you'd change the extension as soon as you copy the file to the final location.

First, you'd best use the pathinfo() function for retrieving the extension:

$extension = pathinfo($_FILES['file']['name'], PATHINFO_EXTENSION);

Then, you'd filter the old extension from the filename, and append the new extension:

$newfilename = basename($_FILES['file']['name'], $extension).$newextension;

Edit: instead of substr and strrpos, I've now used basename() with the extension as a suffix to retrieve the filename, which makes the code shorter and more readable.

And copy the file to its new location:

copy($_FILES['file']['tmp_name'], 'full/path/to/your/videos/'.$newfilename);