Re: [PHP] Send XML file with curl functions
Option 2 is what I'm trying to do, but the problem is that when curl sends the file over the command line, when it's processes via PHP the attached file comes over $_FILES. But, added the postdata obviously doesn't allow it to come over that way. Is there any way to use option 2 and transmit the file so it will come over under $_FILES? -- Aaron Bojan Tesanovic wrote: On Apr 12, 2008, at 11:37 PM, Aaron Axelsen wrote: I am trying to create the following command with the php curl functions: curl -F "[EMAIL PROTECTED]" "http://path/to/api"; The problem i'm having is that i'm creating the xml file with php - so the contents are stored in a variable. How can I send the contents of that variable via curl? I thought just assigning the xml variable to data would work - but it hasn't. Any suggestions? -- Aaron Axelsen [EMAIL PROTECTED] Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php What I can suggest 1. save the XML to file eg xmldata.xml and use system('curl -F "[EMAIL PROTECTED]" "http://path/to/api"; '); 2. or Use PHP CURL functions fufunction postData($postFileds,$url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST ,1); curl_setopt($ch, CURLOPT_POSTFIELDS,$postFileds); curl_setopt($ch, CURLOPT_FOLLOWLOCATION ,1); curl_setopt($ch, CURLOPT_HEADER ,0); // DO NOT RETURN HTTP HEADERS curl_setopt($ch, CURLOPT_RETURNTRANSFER ,1); // RETURN THE CONTENTS OF THE CALL $data = curl_exec($ch); curl_close($ch); return $data; } $xmlData = 'some xml data'; $postFileds = 'data='. urlencode($xmlData); //call function postData($postFileds,"http://path/to/api";); --- Bojan http://www.carster.us/ -- Aaron Axelsen [EMAIL PROTECTED] Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Send XML file with curl functions
On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen <[EMAIL PROTECTED]> wrote: > Option 2 is what I'm trying to do, but the problem is that when curl > sends the file over the command line, when it's processes via PHP the > attached file comes over $_FILES. > im lost here. in option 2 from Bojan's post there is no attached file. there is only a variable that happens to store xml. if php is handling the request on the system hosting $url from said post then the xml data will be made available in the $_POST array albiet the 'data' index. ergo, php on said system would look something like this > But, added the postdata obviously doesn't allow it to come over that > way. Is there any way to use option 2 and transmit the file so it will > come over under $_FILES? i dont understand the 'need' to have the request data available in the $_FILES array; whats wrong w/ $_POST ? -nathan
Re: [PHP] Need a simple one time search utility
On Sat, Apr 12, 2008 at 4:31 PM, Al <[EMAIL PROTECTED]> wrote: > I know how to script one to do the job; but, I was hoping to save a few > hours.. here; ill spare you the few hours ;) as it stands this is designed to be invoked from the cli, but theres a class in here that does all the heavy lifting. im sure you can easily adapt it to suit your needs, but likely you can use it out-of-the-box. there are some limitations, recursive only searches path / filename of matches not returned cant pipe to it as in command | php grep.php args [flags] simple php implementation of grep note: this version is recursive only a flag = 1 will invert the search so that results that do not match will be returned USAGE; } class Grep { const PREG_GREP_STD = 0; const PREG_GREP_INVERT = 1; // <- ganked from quercus ;) private $matches = array(); private $pattern = null; private $path = ''; private $flags = ''; public function __construct($pattern, $path, $flags=0) { $this->pattern = $pattern; $this->path = $path; $this->flags = $flags; $this->search(); } public static function simpleFactory($pattern, $path, $flags=0) { return new self($pattern, $path, $flags); } public function setPattern($pattern) { $this->pattern = $pattern; } public function setPath($path) { if(is_dir($path) || is_file($path)) { $this->path = $path; } } public function setFlags($flags) { $this->flags = $flags; } public function search() { $rdi = new RecursiveDirectoryIterator($this->path); foreach(new RecursiveIteratorIterator($rdi, RecursiveIteratorIterator::SELF_FIRST) as $curFile) { $this->matches = array_merge($this->matches, preg_grep("/{$this->pattern}/", file($curFile))); } } public function __toString() { return implode($this->matches); } } ?> enjoy, -nathan
Re: [PHP] Importing / Adding Fields Into MySql From A List
revDAVE wrote: Newbie question! I have a list of field names from another database (not mysql) - like: name phone1 phone2 street city state zip info etc (a bunch more fields) Q: Is there a way I can add these to an existing empty/blank table? I have phpMyAdmin and If there's a way add tables w / php - maybe that would work also If I can just get all the field names in the table as text fields - that would be ok for now - then I can individually change the field type by hand w phpMyAdmin... BTW: What is the best field type for 'average' text (not large 'BLOBS') like: 1 - Street address - maybe less than 255 characters 2 - Info field - maybe more than 255 characters - (let's assume that user might want to search on the fields): -text? -char? -TINYTEXT? -mediumtext? -varchar? -longtext? Q: Is there a url to read about the types? I'm looking at these now but not quite sure ... http://dev.mysql.com/doc/refman/5.1/en/char.html http://dev.mysql.com/doc/refman/5.1/en/blob.html Dave, You really want to take you MySQL questions to a MySQL list. Also, for using PHPMyAdmin, RTFM as it tells you how to use it with your table. Wolf -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Send XML file with curl functions
The problem is that it is a 3rd party API that I am trying to submit data to. I have submitted a request to make the necessary changes for what I'm trying to do. Nathan Nobbe wrote: On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen <[EMAIL PROTECTED]> wrote: Option 2 is what I'm trying to do, but the problem is that when curl sends the file over the command line, when it's processes via PHP the attached file comes over $_FILES. im lost here. in option 2 from Bojan's post there is no attached file. there is only a variable that happens to store xml. if php is handling the request on the system hosting $url from said post then the xml data will be made available in the $_POST array albiet the 'data' index. ergo, php on said system would look something like this But, added the postdata obviously doesn't allow it to come over that way. Is there any way to use option 2 and transmit the file so it will come over under $_FILES? i dont understand the 'need' to have the request data available in the $_FILES array; whats wrong w/ $_POST ? -nathan -- Aaron Axelsen [EMAIL PROTECTED] Great hosting, low prices. Modevia Web Services LLC -- http://www.modevia.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Send XML file with curl functions
You should read PHP manual more often it is a bible for us :) http://www.php.net/curl_setopt there is example on that page how to upload files. You need to save data to disk first though, which I guess is not a big deal to do the job On Apr 14, 2008, at 2:47 AM, Aaron Axelsen wrote: The problem is that it is a 3rd party API that I am trying to submit data to. I have submitted a request to make the necessary changes for what I'm trying to do. Nathan Nobbe wrote: On Sun, Apr 13, 2008 at 1:07 PM, Aaron Axelsen <[EMAIL PROTECTED]> wrote: Option 2 is what I'm trying to do, but the problem is that when curl sends the file over the command line, when it's processes via PHP the attached file comes over $_FILES. im lost here. in option 2 from Bojan's post there is no attached file. there is only a variable that happens to store xml. if php is handling the request on the system hosting $url from said post then the xml data will be made available in the $_POST array albiet the 'data' index. ergo, php on said system would look something like this But, added the postdata obviously doesn't allow it to come over that way. Is there any way to use option 2 and transmit the file so it will come over under $_FILES? i dont understand the 'need' to have the request data available in the $_FILES array; whats wrong w/ $_POST ? -nathan -- Aaron Axelsen [EMAIL PROTECTED] Great hosting, low prices. Modevia Web Services LLC -- http:// www.modevia.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Bojan Tesanovic http://www.carster.us/
[PHP] Writing MySQL Update Query with NULL value
I'm trying to write a MySQL UPDATE query where one or more variables may be NULL. So, I'm trying something like: $last_name = $_POST['last_name']; $first_name = $_POST['first_name']; $suffix = $_POST['suffix']; $suffix = empty($suffix) ? NULL : $suffix; $phone = $_POST['phone']; $phone_index = $_POST['phone_index']; $update_query = "UPDATE 'phones' SET 'last_name' = $last_name, 'first_name' = $first_name, 'suffix' = $suffix, 'phone' = $phone WHERE 'phone_index' = $phone_index;"; However, when I echo out this query, I get: UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = , 'phone' = 123-456-7890 WHERE 'phone_index' = 323; I think, for this to properly update the record, it should be: UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = NULL, 'phone' = 123-456-7890 WHERE 'phone_index' = 323; What am I doing wrong? -= Bill =- -- Nothing is so bad that it can't get worse. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Writing MySQL Update Query with NULL value
Bill Guion wrote: I'm trying to write a MySQL UPDATE query where one or more variables may be NULL. So, I'm trying something like: $last_name = $_POST['last_name']; $first_name = $_POST['first_name']; $suffix = $_POST['suffix']; $suffix = empty($suffix) ? NULL : $suffix; $phone = $_POST['phone']; $phone_index = $_POST['phone_index']; $update_query = "UPDATE 'phones' SET 'last_name' = $last_name, 'first_name' = $first_name, 'suffix' = $suffix, 'phone' = $phone WHERE 'phone_index' = $phone_index;"; However, when I echo out this query, I get: UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = , 'phone' = 123-456-7890 WHERE 'phone_index' = 323; I think, for this to properly update the record, it should be: UPDATE 'phones' SET 'last_name' = Doe, 'first_name' = John, 'suffix' = NULL, 'phone' = 123-456-7890 WHERE 'phone_index' = 323; 1) You don't need quotes around your field names. 2) You do need quotes around your data, plus you should use mysql_real_escape_string to stop sql injection attacks: $phone = mysql_real_escape_string($_POST['phone']); 3) What error do you get once you fix both of those up? Your query should end up looking like: $query = "UPDATE phones SET last_name='" . mysql_real_escape_string($_POST['last_name']) . "', ... or $last_name = mysql_real_escape_string($_POST['last_name']); $first_name = mysql_real_escape_string($_POST['first_name']); // set a default of NULL $suffix = "NULL"; if (!empty($_POST['suffix'])) { // note - you need to add the quotes around the data here $suffix = "'" . mysql_real_escape_string($_POST['suffix']) . "'"; } $query = "UPDATE phones set last_name='${last_name}', first_name='${first_name}' ..., suffix=${suffix}"; -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Evaluating math without eval()
On Sat, 2008-04-12 at 09:05 -0500, Ray Hauge wrote: > > you might be able to leverage a call to expr on a bash sell. Just > replace the variables you're expecting with preg_replace or some similar > function. > > http://hacktux.com/bashmath > http://sysblogd.wordpress.com/2007/08/26/let-bash-do-the-math-doing-calculations-using-that-bash/ > > I'm not sure if that's any more secure than eval though. Good idea Ray. I'm thinking that it might be safer to exec a separate app - preferably sandboxed. That way it could still be PHP (or anything else really) but without the headache of compromising the main application. J -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php