User profile picture not working for PDF generation

User profile picture not working for PDF generation

by Gavin Neale -
Number of replies: 2

Hi Everyone,

I have a problem with trying to retrieve user profile pics for inclusion in a mpdf60 PDF file. I have used solutions from other forum posts here to get the URL code and this works. I can can enter the direct URL in a browser or into a PHP echo statement and the picture appears perfectly eg:

http://XXXXXXXX/moodle/pluginfile.php/1267/user/icon/f1

and 

http://XXXXXXX/user/pix.php/USERID/f1.jpg


But when I enter the same code into my PHP mpdf60 page, moodle retrieves the grey avatar picture instead of the correct image. (You know the grey image when a user does not have a picture uploaded). Any idea why the same URL returns the image to HTML but an avatar for mpdf60? I am not assuming that anyone will be able to help me with mpdf but maybe you know why the moodle returns two different values based on the exact same URL? Is there some sort of context or security that I need to take into account?


Moodle 3.1.1+ (Build: 20160714)


Thanks,

Gavin

Average of ratings: -
In reply to Gavin Neale

Re: User profile picture not working for PDF generation

by Gavin Neale -

As an example of what I mean for those without mpdf.

If I have this URL for a known userid and I paste it into a web browser I get the correct image but if I copy the file to a tmp.png I get the grey avatar. Any ideas about what I am doing wrong?


$url = 'http://XXXXXXXXX/moodle/user/pix.php/241/f1.jpg';

$img = 'tmp.png';

file_put_contents($img, file_get_contents($url));


The above also works when I can replace the URL with a file and it copies the file okay and if I put a broken link I get a corrupted tmp.png. But the above returns the grey avatar.

In reply to Gavin Neale

Re: User profile picture not working for PDF generation

by Gavin Neale -

Sorry I have moved the question to the Moodle Development forum. Is there any way to remove these posts from here?