Jump to content

Executing outside script using exec()


chonk

Recommended Posts

I have a page that makes a call to an outside php page that creates a txt file and stores it on the server, attaches the file to an email then deletes it.
 
Everything works except the bolded line of:
exec('/home/terra/public_html/CreateDealerCatalogDB.php?ID=$DealerID&save=1');
 
I initially tried using this:
<img src='/CreateDealerCatalogDB.php?ID=$DealerID&save=1' width='1' height='1'>
which worked but only after submitting twice as the <img> tag got executed AFTER the php.
 
Everything I read says the "exec()" function is what I want to do but I can't for the life of me figure out why it doesnt work.
 
Heres what I have:
 

$text = "$TransDesc \n\n $CustomizationInfo";
if($includeLogo == "1"){$path_of_logo = "../../images/dealers/dealerLogos/hires/$LogoHi";}
if($includeDB == "1"){
//create a copy of catalogDB to attach
exec('/home/terra/public_html/CreateDealerCatalogDB.php?ID=$DealerID&save=1');
$path_of_db = "../../images/dealers/db$DealerID.csv";
}
$from = "[email protected]";
$subject = "Dealer Order";
$email = "[email protected]";
$to = "[email protected]";

include_once('../../PEAR/PEAR/Mail.php');
include_once('../../PEAR/PEAR/Mail/mime.php');
$message = new Mail_mime();
$message->setTXTBody($text);
//$message->addAttachment($path_of_logo);
$message->addAttachment($path_of_db);
$body = $message->get();
$extraheaders = array("From"=>$from, "Subject"=>$subject,"Reply-To"=>$email);
$headers = $message->headers($extraheaders);
$mail = Mail::factory("mail");
$mail->send($to, $headers, $body);
if($includeDB == "1"){
//destroy created db
exec('/home/terra/public_html/CreateDealerCatalogDB.php?ID=$DealerID&delete=1');

And again the flow is:

  • My php page executes an outside file with the path of /home/terra/public_html/CreateDealerCatalogDB.php?ID=$DealerID&save=1'
  • outside file creates a txt file on my server
  • php page attaches file to mail.sends
  • php file deletes txt file

Any help will be greatly appreciated as i've struggled for an entire day on this already.

Link to comment
https://forums.phpfreaks.com/topic/276783-executing-outside-script-using-exec/
Share on other sites

exec() is for executing files. There is no such file as "CreateDealerCatalogDB.php?ID=123&save=1". There is one called "CreateDealerCatalogDB.php" though.

 

Why not just include() the file normally?

$get = $_GET; // save old values
$_GET["ID"] = $DealerID;
$_GET["save"] = 1;
include $_SERVER["DOCUMENT_ROOT"] . "/CreateDealerCatalogDB.php";
$_GET = $get; // restore

@regunix, I think he wants to execute a php GET variable by terminal.

 

My suggestion:

<?php

$DealerID = $_GET['DealerID']; 

//create a copy of catalogDB to attach
exec("php-cgi -f /home/terra/public_html/CreateDealerCatalogDB.php ID=$DealerID save=1");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.