Page 1 of 1

How to edit large files in Binary using php

Posted: Sun Dec 05, 2010 5:58 pm
by Rksk
Experts,

I want to replace a set of binary charators in some files (1-2MB sized) using php.

I tried below functions. but they got overflow when loading file to variable.

Code: Select all

    function gethex()
    {
    $file = 'source.mp3';
        $handle = fopen($file, 'r') or die('permission?');
        
            while(!feof($handle))
            {
                foreach(unpack('C*',fgets($handle)) as $dec)
                {
                    $tmp = dechex($dec);
                    $this->hex[] .= strtoupper(str_repeat('0',2-strlen($tmp)).$tmp);    
                }
            }
        
        return join($this->hex);
    }
    
//****************************************

    function writehex($hexcode)
    {
        $file = 'test.mp3';
        foreach(str_split($hexcode,2) as $hex)
        {
            $tmp .= pack('C*', hexdec($hex));
        }
        
            $handle = fopen($file, 'w+') or die('permission?');
            fwrite($handle, $tmp);
        
    } 


Please tell me another way to do it.

Thankz.

[ Post made via Mobile Device ] Image

Re: How to edit large files in Binary using php

Posted: Mon Dec 06, 2010 12:24 am
by Saman

Re: How to edit large files in Binary using php

Posted: Mon Dec 06, 2010 9:59 pm
by Rksk
Thankz bro.
it worked for me.

[ Post made via Mobile Device ] Image