Jump to content


Photo

fopen() and retrieving a blob from a dynamic URL


  • Please log in to reply
3 replies to this topic

#1 thedust2010

thedust2010
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 18 September 2006 - 09:58 PM

I have a PHP script that accepts various paramters and outputs an image.  It works fine inside of an image tag but I can't use it with fopen() to attach to an email.  For example this HTML will display the custom image just fine:

<img src="http://www.mydomain.com/file.php?fileID=45598&constrain=550" />

BUT using fopen() to attain the image as a blob is just not working:

$fileBlob = fread(fopen("http://www.mydomain.com/file.php?fileID=45598&constrain=550", "r"), $Row_File["fileSize"]);

Any ideas on how this can be handled?  I do have allow_url_fopen set to true, so I'm not sure what the problem is...

#2 ronverdonk

ronverdonk
  • Members
  • PipPipPip
  • Advanced Member
  • 277 posts
  • LocationNetherlands

Posted 18 September 2006 - 11:32 PM

Have you tried the 'file_get_contents' function?

Ronald  8)
RTFM is an almost extinct art form, it should be subsidized.

#3 thedust2010

thedust2010
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 20 September 2006 - 02:46 PM

file_get_contents() does not work either... same result.  The image is a 4 KB empty image file.  :(  Any other ideas?

#4 thedust2010

thedust2010
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 20 September 2006 - 05:54 PM

I finally got this figured out.  I was having problems because I didn't realize when you make a request with fopen() or get_file_contents() it makes that request as an entirely new user with no saved session data.  Since that user is not logged in, it was refusing to serve up the file.  The way around this was to generate a random key, associate it with the file in the DB and then submit that key for validation at /file.php.  The temporary key is then deleted and everyone is happy.  Thanks for your help!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users