Well, I normally do not save PDF files inside a database. It uses extra overhead and runs into many issues. But, let’s think of your code as-is. You load a resource object rsd, but is it not a normal variable. Next, you ENCODE it part of it’s data into another variable. Next, you DECODE that same data back into what it was to start with and save in another variable. So much work, tons of wasted server processing. Makes little sense to me to handle simple PDF files that way.
Anyway, my comments aside, my assumption is that you overflowed the allotted memory allowed. It might that you simply need to add some extra ram to the process. Not physical ram, but, code wise to allow for more than the default amounts allowed. Max allowed can be 80Megs, 128meg, 256meg, etc.
This depends on how your server is set up and how PHP has be set up. After some minor research,
it appears that the most common default is 128megs per running script. It will alter if using multiple
threads. You can set it like this at the top of the page. ini_set(‘memory_limit’, ‘512MB’);
But, one other issue is that you can drop the extra ENCODE/DECODE lines and just use the already
encoded versions. That might solve it on it’s own. (Variables are held in memory!)
Good luck!