Reply to Re: How to tell if a file is binary

Your name:

Reply:


Posted by Java Boy on 12/06/05 22:28

You might try using file command on linux systems
--
Geeks Home
www.fahimzahid.com




"comp.lang.php" <phillip.s.powell@gmail.com> wrote in message
news:1133895195.014545.139900@g14g2000cwa.googlegroups.com...
> I borrowed the following function from the PHP manual user notes:
>
> [PHP]
> if (!function_exists('is_binary')) {
> /**
> * Determine if a file is binary. Useful for doing file content
> editing
> *
> * @access public
> * @param mixed $link Complete path to file (/path/to/file)
> * @return boolean
> * @link http://us3.php.net/filesystem#30152
> * @see link user notes regarding this created function
> */
> function is_binary($link) {
> $tmpStr = '';
> $fp = @fopen($link, 'rb');
> $tmpStr = @fread($fp, 256);
> @fclose($fp);
>
> if ($tmpStr) {
> $tmpStr = str_replace(chr(10), '', $tmpStr);
> $tmpStr = str_replace(chr(13), '', $tmpStr);
>
> $tmpInt = 0;
>
> for ($i = 0; $i < strlen($tmpStr); $i++) {
> if (extension_loaded('ctype')) {
> if(!ctype_print($tmpStr[$i])) $tmpInt++;
> } elseif (!eregi("[[:print:]]+", $tmpStr[$i])) {
> $tmpInt++;
> }
> }
>
> if ($tmpInt > 5) return(0); else return(1);
> } else {
> return(0);
> }
> }
> }
> [/PHP]
>
> Problem is that the results are completely backwards:
>
> [PHP]
> print_r(is_binary("/path/to/my/image.jpg")); // RETURNS 0
> print_r(is_binary("/path/to/my/text.txt")); // RETURNS 1
> [/PHP]
>
> It's basically saying that binary files are ASCII and all ASCII files
> are binary! Is there a better function out there that can tell me if a
> file is binary or not?
>
> Thanx
> Phil
>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация