Paqman
September 5th, 2010, 08:30 PM
I'm playing around with using curl to send a file to my server when a user runs a script.
I'm using curl in my bash script to send the file:
curl -F logfile=~/location/of/logfile http://myserver/target.php
The on the server I have the following PHP, which is supposed to write the posted file to target.txt:
<?php
//
// test page that accepts HTTP POST request only. for demo purpose
// accepts 'logfile' parameter, and records logfile and
// browser user-agent to text files
//
if (isset( $_POST['logfile'])) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
$logfile=$_POST['logfile'];
//log any post request to a textfile
$fh = fopen("target.txt","a+");
$text = "logfile : $logfile ($useragent)";
$text.="\n";
fputs($fh,$text);
fclose($fh);
// the positive response
print "data was submitted successfully";
} else {
// the negative response
print "this page only accepts POST request";
}
?>
Can't get it to work though, i'm getting 500 Internal Server Error. I'm not really gripped up on PHP, I got target.php from here (http://linux.byexamples.com/archives/311/sending-http-post-using-curl-command/), is this the problem?
I'm using curl in my bash script to send the file:
curl -F logfile=~/location/of/logfile http://myserver/target.php
The on the server I have the following PHP, which is supposed to write the posted file to target.txt:
<?php
//
// test page that accepts HTTP POST request only. for demo purpose
// accepts 'logfile' parameter, and records logfile and
// browser user-agent to text files
//
if (isset( $_POST['logfile'])) {
$useragent = $_SERVER['HTTP_USER_AGENT'];
$logfile=$_POST['logfile'];
//log any post request to a textfile
$fh = fopen("target.txt","a+");
$text = "logfile : $logfile ($useragent)";
$text.="\n";
fputs($fh,$text);
fclose($fh);
// the positive response
print "data was submitted successfully";
} else {
// the negative response
print "this page only accepts POST request";
}
?>
Can't get it to work though, i'm getting 500 Internal Server Error. I'm not really gripped up on PHP, I got target.php from here (http://linux.byexamples.com/archives/311/sending-http-post-using-curl-command/), is this the problem?