Here is my problem. I have a ticket-tracking system that is not very ‘user friendly’ but I have a desire for my users to submit ‘tickets’ to the system without having them to see it.
I got as far as just using a custom HTTP Form and posting to the ticket tracking system. One problem is the ‘success/completion’ page has a tendency to confuse people. So I figured… well since I cant change the ticket system to use a different ‘success’ page. I will just handle the HTTP Post exchange with CURL and report a custom success or problem page. Heres some abstracted code.
File: tickethelper.php
<?php
extract($_POST);
$url = 'TICKETSYSTEMURL';
$fields = array(
'fullname'=>urlencode($fullname),
/*many more fields*/
);
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string,'&');
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);
curl_setopt($ch, CURLOPT_MAXREDIRS, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$contents = curl_exec($ch);
curl_close($ch);
if((strlen(strstr($contents,'Your ticket has been submitted')))>0){
header("Location: http://THANKYOU");
}
else{
header("Location: http://OOPS");
}
?>
However, what I realized is that I am missing my file upload. Most of the CURL examples I have seen are to do with uploading local files to a remote HTTP POST page.
How do I handle receiving a file from my users HTTP form, process this in the ‘tickethelper’ and POST that to the ‘TICKETSYSTEMURL’ ?
-Israel
Well, I can’t say I’ve done this myself, but according to the PHP documentation regarding CURL and File Handling (PHP.net)
You should be able to call
fopen()on the file that has been uploaded (refer to documentation regarding Handling File Uploads) I’m not sure, but you may need to callmove_uploaded_file()to a controlled directory on the server before callingfopen()For example: