Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8287721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:07:29+00:00 2026-06-08T12:07:29+00:00

I’m new to Joomla and PHP dev so bear with me. Pulling some simple

  • 0

I’m new to Joomla and PHP dev so bear with me.

Pulling some simple data after a quiz to draw a certificate image. I need users to click on a link and download that image.

Once again, I can get something working outside of Joomla but not within. I haven’t even gotten to the dynamically created image yet and running into issues with just a static one, namely the file downloaded is invalid.

Here’s one script I was able to get working outside of Joomla, using the template preview as an existing image:

<?php
header("Content-type: image/png");  
header('Content-Disposition: attachment; filename="template_preview.png"');  
readfile('template_preview.png');  

When downloaded the image is correct.

However, in my Joomla file:

<?php defined('_JEXEC') or die;
require_once("includes/variables_certificate.php"); 
header("Content-type: image/png");  
header("Content-Type: application/octet-stream");  
header('Content-Disposition: attachment; filename="template_preview.png"');  
$filename = JPATH_SITE.'/templates/'.$this->template.'/template_preview.png';  
readfile($filename);  

I get an invalid image. This isn’t even the part where I’m pulling in the dynamic image yet :/

Any ideas?

The only other thread I could find from Joomla was here and not quite the same issue: Forcing file download in PHP – inside Joomla framework
Also followed a bunch of examples in here: http://php.net/manual/en/function.header.php

Thanks all in advance!

#############################################

Partial Solution working for static image (thanks @Chris!), trying to get the dynamic image to work though

download.php:

<?php
require_once("includes/variables_certificate.php");
defined('_JEXEC') or die;
// $filename = JPATH_SITE.'/templates/'.$this->template.'/template_preview.png'; //works
$filename = JURI::root().'index.php?tmpl=certgenerator&quizmod='.$quizmod; //Not working

header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="certificate.png"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean();
flush();
readfile($filename);
exit;

and the certgenerator.php:

defined('_JEXEC') or die;
require_once("includes/variables_certificate.php");

$image_file = JPATH_SITE.'templates/'.$this->template.'/images/certificate_page.png'; 
$my_img = imagecreatefrompng ($image_file);
$font_size_big = 24;
$text_color = imagecolorallocate( $my_img, 0, 255, 0 );
$font_file = JPATH_SITE.'templates/'.$this->template.'/FelipaRegular.ttf';  

imagefttext( $my_img, $font_size_big, 0, 55, 75, $text_color, $font_file, "why u no work"); //if commented out image displays but not font obviously, as it's written now it returns a blank page
imagestring( $my_img, 4, 30, 25, "works", $text_color ); //works but doesn't include font

header( "Content-type: image/png" );
imagepng( $my_img );

imagecolordeallocate( $text_color );
imagedestroy( $my_img );
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T12:07:32+00:00Added an answer on June 8, 2026 at 12:07 pm

    Use output buffering and flush the file to the browser. Might also want to be sure that defined('_JEXEC') returns true.

    <?php
    require_once("includes/variables_certificate.php");
    defined('_JEXEC') or die;
    $filename = JPATH_SITE.'/templates/'.$this->template.'/template_preview.png';
    
    header('Content-Description: File Transfer');
    header('Content-Type: application/octet-stream');
    header('Content-Disposition: attachment; filename='.basename($filename));
    header('Content-Transfer-Encoding: binary');
    header('Expires: 0');
    header('Cache-Control: must-revalidate');
    header('Pragma: public');
    header('Content-Length: ' . filesize($filename));
    ob_clean();
    flush();
    readfile($filename);
    exit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.