Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.

Using PHP to process submitted PDF Form and Upload FDF to Server

Avatar

Level 7

Searching around the  forums I found the PHP script below.

Can someone please quide me how I can make this code to work for me?

I have install PHP and MySQL locally for testing-Do I need anything else to install?

Where and what folder I have to put this PHP script?

What my http will be( I will use localhost) for the submit botton?

Where the pdf file with the data wll be stored?

I see these name below in the PHP script but I can not make out what stand for....

administrator/xml

administrator/pdf

THANK you

This is PHP code for sending an XML file via HTTP Submit into a MySQL database:

<? require_once("configuration.php"); $conf=new JConfig(); $con=mysql_connect($conf->host,$conf->user,$conf->password);
mysql_select_db('wilder_joomla',$con);

define('ADMIN_ROOT_DIR',dirname(__FILE__));
$xml_uploaddir = ADMIN_ROOT_DIR."/administrator/xml/";
$pdf_uploaddir = ADMIN_ROOT_DIR."/administrator/pdf/";

function random($length)
    {
        $hash =date('YmdHis',time()+8*3600)."_";
        $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
        $max = strlen($chars) - 1;
        mt_srand((double)microtime() * 1000000);
            for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; }

$file_path = $xml_uploaddir.random(10).".xml";
$temp = split("/",$file_path);
$xml_path = $temp[count($temp)-2]."/".$temp[count($temp)-1];

$body = file_get_contents("php://input");
$fp=fopen($file_path,"w");
fwrite($fp,$body);
fclose($fp);

$xml=simplexml_load_file($file_path);
$nodes=$xml->xpath("/form1/P1");
$xml_groupname=$nodes[0]->group_name[0];
$xml_groupname=addslashes($xml_groupname);
$xml_checkin_date=$xml->DateofArrival;
$xml_contact_person=$nodes[0]->contact_name[0];
$xml_contact_email=$nodes[0]->contact_email[0];
/*
print_r("FilePath: $file_path
");
print_r("GroupName: $xml_groupname
");
print_r("checkin_date: $xml_checkin_date
");
print_r("contact_person: $xml_contact_person
");
print_r("contact_email: $xml_contact_email
");
*/
$sql = "insert into jos_xml_files (status,file_path,pdf_path,group_name,checkin_date,contact_person,userid,add_time,email) values (0,'$xml_path','','$xml_groupname','$xml_checkin_date','$xml_contact_person',0,now(),'$xml_contact_email')";
mysql_query($sql);
$message ='
XML file is uploaded successfully.';
mysql_close($con);
?>

0 Replies