I am working on a school project which involves a Supermarket system and I have a Shop PC (localhost) and a HQ server (hosted on Amazon EC2). One of the requirements is that Shop PC will generate a transaction file (I have a button which generates the file) and that text file needs to be sent over to the HQ server. I have created a folder with 777 permissions on the HQ server. I was trying to simply send over/upload the file to that folder using the copy function of PHP but that does not work. Any clues on how I can do that? I do not have ftp installed on amazon and cannot do that as per the requirements.
Also, i cannot create an upload form (multipart form?) on the HQ admim to upload the file because the shop guy can't access the HQ server pages.
The address of the folder where the files need to be uploaded is:
"site address"/uploads
I create the transaction file in the following manner:
$ourFileName = "transaction.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
//fwrite($fh, $stringData);
$sql = mysql_query("the query");
while($row=mysql_fetch_array($sql)){
$stringData = "data";
fwrite($ourFileHandle, $stringData);
}
fclose($ourFileHandle);
This file is created on the shop PC and i want to send it to the HQ server, where it can be parsed and added to the HQ database. To the send the file to the uploads folder in the HQ sever, i follow the above code with:
$filename = "news.txt";
$newfile = "siteaddress/uploads/" . $filename;
if(copy($ourFileName, $newfile))
{
print("<h3> UPLOAD SUCCESSFUL!</h3>");
}
else
{
print("<h3>ERROR UPLOADING FILE!</h3>");
}
Edit after following the discussions:
The HQ server has php. Infact it has a file parser defined in parse_transaction.php which begins like:
<?php
include "../storescripts/connect_to_mysql_HQ.php";
mysql_query($sql);
mysql_query($sql2);
mysql_query($sql3);
$filename= mysql_real_escape_string($_FILES["file"]["tmp_name"]);
$lines = file($filename); // slurp file and split into an array by lines
perhaps somehow possible to send the transaction file directly here for parsing and updating without storing it in the uploads folder?