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 = "info@xxx.com";
$subject = "Dealer Order";
$email = "info@xxx.com";
$to = "info@xxx.com";

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
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
Link to comment
Share on other sites

@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");
Edited by jazzman1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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