3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** text/plain になるパターン */ // 一時的なファイルを作成する $temp = tmpfile(); // ファイルに2行のCSVデータを書き込む fwrite($temp, "header1,header2\n"); fwrite($temp, "data1,data2\n"); // 一時ファイルのパスを取得する $meta_data = stream_get_meta_data($temp); $path = $meta_data["uri"]; // mime_content_type関数を使用してファイルのMIMEタイプを取得する $ret = mime_content_type($path); var_dump($ret); // string(10) "text/plain" // ファイルを閉じる(一時ファイルは自動的に削除されます) fclose($temp); /** text/csv になるパターン */ // 一時的なファイルを作成する $temp = tmpfile(); // ファイルに3行のCSVデータを書き込む fwrite($temp, "header1,header2\n"); fwrite($temp, "data1,data2\n"); fwrite($temp, "data3,data4\n"); // 一時ファイルのパスを取得する $meta_data = stream_get_meta_data($temp); $path = $meta_data["uri"]; // mime_content_type関数を使用してファイルのMIMEタイプを取得する $ret = mime_content_type($path); var_dump($ret); // string(8) "text/csv" // ファイルを閉じる(一時ファイルは自動的に削除されます) fclose($temp);
Output for 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
string(10) "text/plain" string(8) "text/csv"
Output for 8.0.0 - 8.0.30
string(10) "text/plain" string(15) "application/csv"
Output for 5.3.1 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
string(10) "text/plain" string(10) "text/plain"
Output for 5.3.0
string(28) "text/plain; charset=us-ascii" string(28) "text/plain; charset=us-ascii"
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Fatal error: Call to undefined function mime_content_type() in /in/gl9C2 on line 13
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Notice: Undefined index: uri in /in/gl9C2 on line 11 Fatal error: Call to undefined function mime_content_type() in /in/gl9C2 on line 13
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Notice: Undefined index: uri in /in/gl9C2 on line 11 Fatal error: Call to undefined function: mime_content_type() in /in/gl9C2 on line 13
Process exited with code 255.
Output for 4.3.2 - 4.3.11, 4.4.0 - 4.4.4
Notice: Undefined index: uri in /in/gl9C2 on line 11 Fatal error: Call to undefined function: mime_content_type() in /in/gl9C2 on line 13
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Notice: Undefined index: uri in /in/gl9C2 on line 11 Fatal error: Call to undefined function: mime_content_type() in /in/gl9C2 on line 13

preferences:
362.74 ms | 402 KiB | 470 Q