PDA

View Full Version : تسخیص mime type



memir
چهارشنبه 29 مهر 1383, 22:43 عصر
سلام
من می خواستم بدونم چه جوری می شه mime type یه فایل رو تشخیص داده. آیا function خاصی برای این کار وجود داره یا نه؟
من خودم mime_content_type رو امتحان کردم ولی جواب نداد.
یه نکته اینکه این کار رو نمی خوام موقع upload کردن انجام بدم. می دونم اون موقع راحت می شه تشخیص داد. فرض کنید فایل در سرور موجوده و می خواهیم نوع فایل رو تشخیص بدیم.

oxygenws
پنج شنبه 30 مهر 1383, 07:44 صبح
تا اونجایی که من می دونم چاره جز همین mime_content_type نداری. (یک توسعه pecl هم وجود داره که بی خیال :) )

البته چند مورد هست که باید رعایت بشه:

You must compile PHP with the configure switch --with-mime-magic to get support for mime-type functions. The extension needs a copy of the simplified magic file that is distributed with the Apache httpd.

Note: The configure option has been changed from --enable-mime-magic to --with-mime-magic since PHP 4.3.2

Note: This extension is not capable of handling the fully decorated magic file that generally comes with standard Linux distro's and is supposed to be used with recent versions of file command.

Note to Win32 Users: In order to use this module on a Windows environment, you must set the path to the bundled magic.mime file in your php.ini.

موفق باشید، امید

memir
جمعه 01 آبان 1383, 22:28 عصر
ممنون از جوابتون
این mime_content_type خروجی که می ده یه خورده ایراد داره مثلا فایل exe رو می ده text/plain یا یه چیزی تو این مایه ها ولی به هر حال در آخر درست کار می کنه!
خلاصه جواب می ده! یه فایل exe گذاشتم باهاش test کردم. درست کار کرد.
هم تو ویندوز هم توی لینوکس.

oxygenws
شنبه 02 آبان 1383, 04:04 صبح
خوبه :)
موفق باشید :)