How Do I Insert File Contents into Response?

I set up a Twilio number so a client could have a SMS keyword response setup… but I don’t know how to get the contents of a file to be returned as the response. I am using the php functions…

I setup a system so that my client could change the responses to different keywords. Basicly it uses a webform to change the contents of a file which gets returned as a response.

What I need to know is how to read in the contents of the file into this function:

BTW… this works fine and will return “READ_FILE_CONTENTS_INTO_HERE”

function app(){
$response = new Services_Twilio_Twiml();
$response->sms(“READ_FILE_CONTENTS_INTO_HERE”);
echo $response;
}

I tried this but it stopped the script dead:

function app(){
$response = new Services_Twilio_Twiml();
$response->sms("<?php include 'file.txt'; ?>");
echo $response;
}

Any ideas?

Thanks

BTW… below is the entire php script:

<?php /* Include twilio-php, the official Twilio PHP Helper Library, * which can be found at * http://www.twilio.com/docs/libraries */ include('Services/Twilio.php'); /* Controller: Match the keyword with the customized SMS reply. */ function index(){ $response = new Services_Twilio_Twiml(); $response->sms("Thank You For Contacting SweetLeafAZ.com - Reply with one of the following keywords: APP = Make Appt, CS = Current Strains, DP = Delivery Prices, SP = Current Specials."); echo $response; } function app(){ $response = new Services_Twilio_Twiml(); $response->sms("http://www.vcita.com...01f2c7d/home"); echo $response; } function cs(){ $response = new Services_Twilio_Twiml(); $response->sms("http://mobile.dudamo...sweetleafaz2"); echo $response; } function dp(){ $response = new Services_Twilio_Twiml(); $response->sms("As of Sept 26 2014, Our Delivery Rates are $2 per mile during the hours of 9am to 6pm. No deliveries will be made after 6pm."); echo $response; } function sp(){ $response = new Services_Twilio_Twiml(); $response->sms("We are currently offering FREE delivery within 10 miles for orders over $100."); echo $response; } /* Read the contents of the 'Body' field of the Request. */ $body = $_REQUEST['Body']; /* Remove formatting from $body until it is just lowercase characters without punctuation or spaces. */ $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); $result = trim($result); $result = strtolower($result); /* Router: Match the ‘Body’ field with index of keywords */ switch ($result) { case 'app’': app(); break; case 'cs': cs(); break; case 'dp': dp(); break; case 'sp': sp(); break; /* Optional: Add new routing logic above this line. */ default: index(); }

Include won’t read the file.

You probably want readfile [url=http://php.net/manual/en/function.readfile.php[url] or file_get_contents [url]http://php.net/manual/en/function.file-get-contents.php]http://php.net/manual/en/function.readfile.php[url] or file_get_contents http://php.net/manual/en/function.file-get-contents.php

Readfile will read the file directly into the output buffer, and file_get_contents will load the file into memory.

Sponsor our Newsletter | Privacy Policy | Terms of Service