{"id":15022553,"url":"https://github.com/oops-org-php/mod_magic","last_synced_at":"2025-05-13T16:31:30.126Z","repository":{"id":254606330,"uuid":"59419695","full_name":"OOPS-ORG-PHP/mod_magic","owner":"OOPS-ORG-PHP","description":"PHP file magic extension","archived":false,"fork":false,"pushed_at":"2022-02-16T18:19:45.000Z","size":195,"stargazers_count":3,"open_issues_count":0,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-10-13T12:03:43.271Z","etag":null,"topics":["libmagic","php","php4","php5","php7","php8"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/OOPS-ORG-PHP.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-05-22T15:32:17.000Z","updated_at":"2024-09-26T04:30:10.000Z","dependencies_parsed_at":"2024-08-24T18:39:15.785Z","dependency_job_id":null,"html_url":"https://github.com/OOPS-ORG-PHP/mod_magic","commit_stats":null,"previous_names":["oops-org-php/mod_magic"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OOPS-ORG-PHP%2Fmod_magic","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OOPS-ORG-PHP%2Fmod_magic/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OOPS-ORG-PHP%2Fmod_magic/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/OOPS-ORG-PHP%2Fmod_magic/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/OOPS-ORG-PHP","download_url":"https://codeload.github.com/OOPS-ORG-PHP/mod_magic/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225246778,"owners_count":17443910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["libmagic","php","php4","php5","php7","php8"],"created_at":"2024-09-24T19:58:06.545Z","updated_at":"2024-11-18T20:25:15.249Z","avatar_url":"https://github.com/OOPS-ORG-PHP.png","language":"C","readme":"# PHP file magic extension\n\n## Description\n\nThis extension is similar to the [fileinfo](https://www.php.net/manual/en/book.fileinfo.php) extension, but only one **filemagic** function is provided to make it a simple use.\n\nThe original name of this package is ```mod_filebin```. It has been changed to ```mod_magic``` since 3.0.1.\n\nThe **filemagic** function returns the same result as the result of the /bin/file command as a string.\n\n***The master branch*** supports PHP 7 and above. For PHP4.3 to PHP 5, use the ```v2``` or ```2.x``` branch.\n\n## Installation\n\n```bash\n[root@host magic]$ phpize\n[root@host magic]$ ./configure\n[root@host magic]$ make test PHP_EXECUTABLE=/usr/bin/php\n[root@host magic]$ make install\n```\n\nIf the libmagic library is not in the OS standard path, use the ```--with-magic=@libMagic_prefix@``` option.\n\n```bash\n[root@host magic]$ phpize\n[root@host magic]$ ./configure --with-magic=/opt/libmagic\n```\n\n## Loading\n\nregist magic.so in php.ini or php sub configuration.\n\n```ini\n; for PHP 7.1 and before\nextension = magic.so\n\n; for PHP 7.2 and after\nextension = magic\n; and also regist with absolute path\nextension = /path/magic.so\n```\n\n## Proto types:\n```php\nfilemagic (string path, int flag = MAGIC_NONE, string magic_path = MIGIC_FILE): string|false\nfilemagic (string path, string magic_path = MIGIC_FILE, int flag = MAGIC_NONE): string|false\n```\n\nThe 2th argument and the 3th argument can be swapped with each other.\n\n**Return value :**\nif success, return mime strings.\nif failure, return false.\n\n\n## Constant\nName | Value\n-- | --\n**MAGIC_FILE** | /usr/share/file/magic\n\n## Flags\nSee also https://github.com/file/file/blob/master/src/magic.h.in\n\nName | Description\n-- | --\n**MAGIC_NONE** | No special handling.\n**MAGIC_DEBUG** | Print debugging messages to stderr.\n**MAGIC_SYMLINK** | If the file queried is a symlink, follow it.\n**MAGIC_COMPRESS** | If the file is compressed, unpack it and look at the contents.\n**MAGIC_DEVICES** | If the file is a block or character special device, then open the device and try to look in its contents.\n**MAGIC_MIME_TYPE** | Return a MIME type string, instead of a textual description.\n**MAGIC_MIME_ENCODING** | Return a MIME encoding, instead of a textual description.\n**MAGIC_CONTINUE** | Return all matches, not just the first.\n**MAGIC_CHECK** | Check the magic database for consistency and print warnings to stderr.\n**MAGIC_PRESERVE_ATIME** | On systems that support utime(2) or utimes(2), attempt to preserve the access time of files analyzed.\n**MAGIC_RAW** | Don't translate unprintable characters to a \\ooo octal representation.\n**MAGIC_ERROR** | Treat operating system errors while trying to open files and follow symlinks as real errors, instead of printing them in the magic buffer.\n**MAGIC_NO_CHECK_APPTYPE** | Check for EMX application type (only on EMX).\n**MAGIC_NO_CHECK_ASCII** | Check for various types of ascii files.\n**MAGIC_NO_CHECK_COMPRESS** | Don't look for, or inside compressed files.\n**MAGIC_NO_CHECK_ELF** | Don't print elf details.\n**MAGIC_NO_CHECK_FORTRAN** | Don't look for fortran sequences inside ascii files.\n**MAGIC_NO_CHECK_SOFT** | Don't consult magic files.\n**MAGIC_NO_CHECK_TAR** | Don't examine tar files.\n**MAGIC_NO_CHECK_TOKENS** | Don't look for known tokens inside ascii files.\n**MAGIC_NO_CHECK_TROFF** | Don't look for troff sequences inside ascii files.\n**MAGIC_MIME** | Returns MIME type with encoding. (MAGIC_MIME_TYPE\\|MAGIC_MIME_ENCODING)\n**MAGIC_APPLE** | Return the Apple creator and type.\n**MAGIC_NO_CHECK_TEXT** | Don't check for text files.\n**MAGIC_NO_CHECK_CDF** | Don't check for cdf files.\n**MAGIC_NO_CHECK_ENCODING** | Don't check text encodings.\n\n\n## Usage\n\n**Most common usage :**\n```php\n\u003c?php\nif ( ($buf = filemagic ('modules/magic.so')) != false )\n    echo \"$buf\\n\";\n?\u003e\n\nResutl:\nELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0b1c92efa1398676c226544835a64d0edd68f491, not stripped\n```\n\n**Execute with custom MAGIC file :**\n```php\n\u003c?php\nif ( ($buf = filemagic ('modules/magic.so', '/usr/share/misc/magic.mgc')) != false )\n    echo \"$buf\\n\";\n?\u003e\n\nResult:\nELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=0b1c92efa1398676c226544835a64d0edd68f491, not stripped\n```\n\n**Get only file mime type :**\n```php\nif ( ($buf = filemagic ('modules/magic.so', MAGIC_MIME_ENCODING)) != false )\n    echo \"$buf\\n\";\n?\u003e\n\nResult:\nbinary\n```\n\n**Get only file mime type with custom MAGIC file :**\n```php\nif ( ($buf = filemagic ('modules/magic.so', MAGIC_MIME, '/usr/share/misc/magic.mgc')) != false )\n    echo \"$buf\\n\";\n?\u003e\n\nResult:\napplication/x-sharedlib; charset=binary\n```\n\n**Can enable to swap 2th and 3th argument each other :**\n```php\nif ( ($buf = filemagic ('modules/magic.so', MAGIC_MIME, '/usr/share/misc/magic.mgc')) != false )\n    echo \"$buf\\n\";\n?\u003e\n\nResut:\napplication/x-sharedlib; charset=binary\n```\n\n**filemagic buffer control :**\n```php\n$buf = file_get_contents ('./php_magic.h');\nif ( ($buf = filemagic ('DATA:' . $fbuf, MAGIC_MIME) != false ) {\n\techo $buf . \"\\n\";\n}\n\nResult:\ntext/x-c; charset=us-ascii\n```\n- if want to get file magic information with buffer data instead of file, use 'DATA:' prefix.\n\n\n**filemagic function error control :**\n```php\n\u003c?php\nif ( ($buf = filemagic ('wrong_path')) == false ) {\n\tif ( version_comapre(PHP_VERSION, '7.2.0', '\u003c') ) {\n\t    //ini_set ('track_errors', true) -\u003e track_errors is SYSTEM_INI, so can't set with ini_set\n\t\tprintf (\"ERROR: %s\\n\", $php_errormsg);\n\t}\n\t$err = error_get_last ();\n\tprint_r ($err);\t\n}\n?\u003e\n\nResult:\nERROR: wrong_path file not found.\nArray\n(\n    [type] =\u003e 2\n    [message] =\u003e wrong_path file not found.\n    [file] =\u003e /some/path/test.php\n    [line] =\u003e 2\n)\n```\n- [$php_errormsg](https://www.php.net/manual/en/reserved.variables.phperrormsg.php) must have the [track_errors](https://www.php.net/manual/en/errorfunc.configuration.php#ini.track-errors) setting enabled.\n- [$php_errormsg](https://www.php.net/manual/en/reserved.variables.phperrormsg.php) was deprecated in 7.2.0 and removed in 8.0.0\n- The filemagic function does not call any error handlers when an error occurs. However, the error message is assigned to [$php_errormsg](https://www.php.net/manual/en/reserved.variables.phperrormsg.php) or [error_get_last ()](https://www.php.net/manual/en/function.error-get-last.php).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foops-org-php%2Fmod_magic","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foops-org-php%2Fmod_magic","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foops-org-php%2Fmod_magic/lists"}