Jump to content

fopen() and retrieving a blob from a dynamic URL


thedust2010

Recommended Posts

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:

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

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

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

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...
Link to comment
Share on other sites

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!!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.