deepu sankar
deepu sankar

Reputation: 4455

base64_encode function return null string when input large string

i created a web service for sending files and that saved in server. The file format is zip. The file size may vary in the user need.

This is my code for before sending data in to server.

   $filename = $_SERVER['DOCUMENT_ROOT'].'/data.zip';

   $data = file_get_contents($filename);
   $new_data = base64_encode($data); 

This new_data variable send to the server. This worked in all small files. But base64_encode return null when i use 5 mb file or larger file.

my problem is that base64_encode is not working in large string i genrated.

if any one know about this please help me.

Upvotes: 0

Views: 539

Answers (1)

Scott Arciszewski
Scott Arciszewski

Reputation: 34113

The answer is simple: file_get_contents() is returning false which, when passed to base64_encode(), results in an empty string.

Why is file_get_contents() failing? It could be any number of reasons:

  • You don't have read permissions on the file. chmod() may help, but it's likely something caused elsewhere.
  • Memory limits prevent file_get_contents() from loading 5 MB of text into memory.
  • Filesystem or disk errors. (Unlikely but strictly possible.)

Upvotes: 1

Related Questions