Question

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?

Was it helpful?

Solution

Does the file get transferred with the wrong write/read/execute attributes or not at all?

If the file does not get transferred have you checked for php log errors?

If you are using copy, then i assume you have the partition mounted so you have direct access to the files on the HQ server, if not you could try setting up your php for receiving files, take a look at this:

http://php.net/manual/en/features.file-upload.post-method.php

And if you don't have php on the server, how do you access its files?

OTHER TIPS

Generate the file in Shop PC and store it somewhere can be accessed (read) by HQ Server.

PHP command copy should be used in HQ Server to get the file from Shop PC.

copy('http://somedomain.com/transaction.txt', '/tmp/transaction.txt');

Note that you need allow_url_fopen has to be = on in php.ini.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top