Hi all, I hope someone will be able to point me in the right direction. I am not a PHP programmer but I need to get a PHP script working to accomplish a different goal and I could use some advice.
I am trying to automate the upload text files to a server. I would like to upload various text files from a linux computer on a nightly basis to a linux server. The set up I am working with so far is like this:
perl/lwp script on client --(http post)--> php script on server
Thus far it is not working, but I think I am close. The perl script on the client is like this:
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request::Common;
my $hostname = hostname;
chomp $hostname;
my $file = "/log/timestamps/time.txt";
my $browser = LWP::UserAgent->new;
my $response = $browser->post('http://10.10.9.4/upload/files.php', Content_Type => 'form-data',
[
'hostname' => $hostname,
'uploadedfile' => [$file],
],
);
die "error: ", $response->status_line
unless $response->is_success;
exit;
The PHP script on the server side, named files.php is exceedingly simple, and does not have the file validation it will eventually have (once I have it working basically):
<?php
$hostname = $_POST['hostname'];
$mkdir = sudo mkdir -p /www/htdocs/users/$hostname;
$webdir = $FILES['uploadedfile'];
$target_path = "/www/htdocs/users/$hostname/";
$target_path = $target_path . basename( $FILES['uploadedfile']['name']);
$FILES['uploadedfile']['tmp_name'];
$output = move_uploaded_file($FILES['uploadedfile']['tmp_name'], $target_path);
?>
According to all off the tutorials and forums and documents I have been pouring over for the last two days, this should work. However, since it does NOT work I am obviously missing something. Perhaps I have been staring at it too long and more eyes could help.
Any suggestions?