#20400 [Bgs]: Doing: base64_encode on JPG & GIF images. Error: The function ends prematurely.

From: Date: Tue, 12 Nov 2002 21:45:54 +0000
Subject: #20400 [Bgs]: Doing: base64_encode on JPG & GIF images. Error: The function ends prematurely.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-24754@lists.php.net to get a copy of this message
ID: 20400 User updated by: dromar84@msn.com Reported By: dromar84@msn.com Status: Bogus Bug Type: *Graphics related Operating System: win32 PHP Version: 4.2.1 New Comment: The problem is fixed by using 'rb'(read binary) instead of 'r'(read) inside of the fopen flag on Win32 platforms. Just another 3-bit mistake by the script writer. Previous Comments: ------------------------------------------------------------------------ [2002-11-12 14:31:03] dromar84@msn.com I intend to use this script to store mutiple image files in a database or in one compressed file. If anyone knows of a better way to accomplish this task, I would appriciate it if you could tell me. p.s. I am aware that using base64_encode will not result in a compressed file. ------------------------------------------------------------------------ [2002-11-12 14:31:01] iliaa@php.net Sorry, but your problem does not imply a bug in PHP itself. For a list of more appropriate places to ask for help using PHP, please visit http://www.php.net/support.php as this bug system is not the appropriate forum for asking support questions. Thank you for your interest in PHP. On windows you need to open binary files with 'rb' not 'r'. If you still experience the problem even after changing the fopen flags try using the latest CVS snapshot. ------------------------------------------------------------------------ [2002-11-12 14:30:51] derick@php.net Please try using this CVS snapshot: http://snaps.php.net/php4-latest.tar.gz For Windows: http://snaps.php.net/win32/php4-win32-latest.zip ------------------------------------------------------------------------ [2002-11-12 14:25:34] dromar84@msn.com The following PHP script is stable on *NIX platforms but unstable on Win32 platorms. <?php $LineLength = 50; $uploadfile = 'PATH TO IMAGE'; $uploadfile_name = 'PATH TO IMAGE'; $fd = fopen ($uploadfile, "r"); $size = filesize ($uploadfile); $c = substr ("$uploadfile_name", strrpos ($uploadfile_name, ".") + 1 ); $cont = fread ($fd, $size); fclose ($fd); $encimg = base64_encode ($cont); $imgcode = chunk_split ("$encimg", $LineLength, "'.'"); print $imgcode; ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=20400&edit=1

« previous php.bugs (#24754) next »