I want to include a PHP file in a function which is inside a drupal module. When I use the function require_once, it shows internal error. That's why I used the function module_load_include.

The code I used is given below :

if (function_exists('drupal_get_path')) {
$file = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uc_file') . '/fpdf/fpdf.php';
$file1 = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uc_file') . '/fpdi/fpdi.php';
$pdffile = DRUPAL_ROOT . '/' . $file_download->full_path;
$savepath = DRUPAL_ROOT . '/' . drupal_get_path('module', 'uc_file') . '/pdfedit/';
module_load_include('php', 'uc_file', 'fpdf/fpdf.php');
module_load_include('php', 'uc_file', 'fpdi/fpdi.php');

Please help me to solve this issue.

Comments

imranweb’s picture

Can you please paste the output here?
What exactly you see as errors?

Check your IF condition braces "{}".

-Imran

Anju1990’s picture

Hi Imran

Thanks for the quick response. The braces are there in the if condition. I am getting a blank page and when inspecting with firebug it shows "NetworkError: 500 Internal Server Error.."

imranweb’s picture

Did you disable the error_reporting?

What exactly you are doing here?
module_load_include('php', 'uc_file', 'fpdf/fpdf.php');
module_load_include('php', 'uc_file', 'fpdi/fpdi.php');

It should be like:
module_load_include('php', 'uc_file', 'fpdi/fpdi');

Don't add .php at the end.

-Imran

Anju1990’s picture

I am trying to edit the ubercart module. I have uploaded fpdf files inside the module. I want to include those files inside the module file. require_once and module_load_include not working. I also tried removing the .php.

imranweb’s picture

Are you sure module_load_include is the reason for error?
Can you check the error log?

Please send the full path of files, which you want to include.

-Imran

Bhanuji’s picture

According to Drupal 7 coding standards, use .inc file than .php file.. If you see core module also we use .inc file.

If u can change .php to .inc file then ...module_load_include($type, $module, $name = NULL) will do your work.

Thanks,
Bhanuji

jaypan’s picture

Bhanu is correct. But your problem can be fixed by doing the following:

module_load_include('php', 'uc_file', 'fpdf/fpdf');

Contact me to contract me for D7 -> D10/11 migrations.
Or anything really. I'm friendly, and open to work or conversation.
seant’s picture

Are you sure the error is coming from those lines of code? Other than the fact that your code above is missing the closing } bracket, I don't see anything that could throw a 500 error.

Narrow down by commenting out each line to see when the error goes away.