Asked  7 Months ago    Answers:  5   Viewed   35 times

I have a form that allow users to upload files, I however need to get the file extension, which I am able to get, but not sure if I'm using the most effective solution

I can get it using the following ways

$fileInfo = pathinfo($_FILES['File']['name']);
echo $fileInfo['extension'];

$ext = end(explode('.',$_FILES['File']['name']));
echo $ext;

Which method is the best to use or are there even better solutions that would get the extension?

 Answers

84

pathinfo($_FILES['File']['name'], PATHINFO_EXTENSION)

  • Use a built-in function whenever possible (what @Sarfraz said in the meantime), and
  • Extract only the needed information (options = PATHINFO_EXTENSION)
Wednesday, March 31, 2021
 
alez
answered 7 Months ago
86

You should point to your vendor/autoload.php at Settings | PHP | PHPUnit when using PHPUnit via Composer.

This blog post has all the details (with pictures) to successfully configure IDE for such scenario: http://confluence.jetbrains.com/display/PhpStorm/PHPUnit+Installation+via+Composer+in+PhpStorm

Related usability ticket: http://youtrack.jetbrains.com/issue/WI-18388

P.S. The WI-18388 ticket is already fixed in v8.0

Wednesday, March 31, 2021
 
ojrac
answered 7 Months ago
79

On Mac OS X environment variables available in Terminal and for the normal applications can be different, check the related question for the solution how to make them similar.

Note that this solution will not work on Mountain Lion (10.8).

Saturday, May 29, 2021
 
Nate
answered 5 Months ago
21
$x = $x - floor($x)
Thursday, June 17, 2021
 
JakeGR
answered 4 Months ago
53

Have a look at MediaInfo project (http://mediaarea.net/en/MediaInfo)

it gets extensive information about most media types, and the library is bundled with a c# helper class which is easy to use.

You can download the library and helper class for windows from here:

http://mediaarea.net/en/MediaInfo/Download/Windows (DLL without installer)

The helper class is located at DevelopersSourceMediaInfoDLLMediaInfoDLL.cs, simply add it to your project and copy the MediaInfo.dll to your bin.

Usage

you can obtain information by requesting specific parameter from the library, Here is a sample:

[STAThread]
static void Main(string[] Args)
{
    var mi = new MediaInfo();
    mi.Open(@"video path here");

    var videoInfo = new VideoInfo(mi);
    var audioInfo = new AudioInfo(mi);
     mi.Close();
}

public class VideoInfo 
{
    public string Codec { get; private set; }
    public int Width { get; private set; }
    public int Heigth { get; private set; }
    public double FrameRate { get; private set; }
    public string FrameRateMode { get; private set; }
    public string ScanType { get; private set; }
    public TimeSpan Duration { get; private set; }
    public int Bitrate { get; private set; }
    public string AspectRatioMode { get; private set; }
    public double AspectRatio { get; private set; }

    public VideoInfo(MediaInfo mi)
    {
        Codec=mi.Get(StreamKind.Video, 0, "Format");
        Width = int.Parse(mi.Get(StreamKind.Video, 0, "Width"));
        Heigth = int.Parse(mi.Get(StreamKind.Video, 0, "Height"));
        Duration = TimeSpan.FromMilliseconds(int.Parse(mi.Get(StreamKind.Video, 0, "Duration")));
        Bitrate = int.Parse(mi.Get(StreamKind.Video, 0, "BitRate"));
        AspectRatioMode = mi.Get(StreamKind.Video, 0, "AspectRatio/String"); //as formatted string
        AspectRatio =double.Parse(mi.Get(StreamKind.Video, 0, "AspectRatio"));
        FrameRate = double.Parse(mi.Get(StreamKind.Video, 0, "FrameRate"));
        FrameRateMode = mi.Get(StreamKind.Video, 0, "FrameRate_Mode");
        ScanType = mi.Get(StreamKind.Video, 0, "ScanType");
    }
}

public class AudioInfo
{
    public string Codec { get; private set; }
    public string CompressionMode { get; private set; }
    public string ChannelPositions { get; private set; }
    public TimeSpan Duration { get; private set; }
    public int Bitrate { get; private set; }
    public string BitrateMode { get; private set; }
    public int SamplingRate { get; private set; }

    public AudioInfo(MediaInfo mi)
    {
        Codec = mi.Get(StreamKind.Audio, 0, "Format");
        Duration = TimeSpan.FromMilliseconds(int.Parse(mi.Get(StreamKind.Audio, 0, "Duration")));
        Bitrate = int.Parse(mi.Get(StreamKind.Audio, 0, "BitRate"));
        BitrateMode = mi.Get(StreamKind.Audio, 0, "BitRate_Mode");
        CompressionMode = mi.Get(StreamKind.Audio, 0, "Compression_Mode");
        ChannelPositions = mi.Get(StreamKind.Audio, 0, "ChannelPositions");
        SamplingRate = int.Parse(mi.Get(StreamKind.Audio, 0, "SamplingRate"));
    }
}

You can easily obtain all information in string format by callingInform():

        var mi = new MediaInfo();
        mi.Open(@"video path here");
        Console.WriteLine(mi.Inform());
        mi.Close();

if you need more information about available parameters, you can simply query all of them by calling Options("Info_Parameters"):

        var mi = new MediaInfo();
        Console.WriteLine(mi.Option("Info_Parameters"));
        mi.Close();
Friday, July 16, 2021
 
treeface
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :