Question

I am working on a php web app . I need to upload a file to the web server, with customer info - customers.csv. but this process needs to be automated ,

The file will be generated in a Point of Sale app , and the app can open a browser window with the url ...

first i taught i would do something like this www.a.com/upload/&file=customers.csv but read on here that is not possible,

then i taught i would set a value for the file upload field and submit form automatically after x seconds. Discovered thats not possible .

Anybody with a solution , will be appreciated .

EDIT

I have tried this and it works ,file is uploaded to remote server is it working only because the php script is running on the same pc where csv is sitting ???

$file = 'c:\downloads\customers.csv';
                $remote_file = 'customers.csv';

                // set up basic connection
                $conn_id = ftp_connect('host.com');

                // login with username and password
                $login_result = ftp_login($conn_id,'user','password');

                // upload a file
                if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
                 echo "successfully uploaded $file\n";
                } else {
                 echo "There was a problem while uploading $file\n";
                }

                // close the connection
                ftp_close($conn_id);
Was it helpful?

Solution 2

This is a bit tricky, but if your CSV is not too long, you could encode it in base64, send to the webserver as a GET parameter and then, in the server side, decode and store it as a CSV file.

If the file is too big to do that, you have to use other method, like the java applet pointed by @D.Schalla or even install and configure a FTP server, and make the Point of Sale app uploads the file there.

Other alternative, specially good if you cannot modify the sale app, is to install a web server in the client side and write a small php script to handle the upload process. In this way, the sale app could call a local url (something like: http:// localhost/upload.php) and it's this script the one in charge to upload the file which can be achieve with a classical HTTP POST, a FTP connection or any other way you can think about.

OTHER TIPS

This is of course not possible, imagine how this could be abused to upload on linux as example the /etc/passwd. The only way it might be possible is to use a Java Applet, but this is for sure not the best way.

You could try to let your PoS Application make a web request with the customers.csv file and let a WebAPI handle the upload, this may be possible, but I have no expierence with Point of Sale Applications.

Best might be, if the solution above cannot be considered, to just prompt the user to provide the file above and check over name + content if it is the correct one.

MY Solution , which will work with out setting up web server on client side.

This is for windows but can be adapted to linux

On client side

Local Application opens cmd and runs this command ftp -n -s:C:\test.scr

WHICH opens test.scr - a file with ftp commands e.g.

open host.com
user1
passwOrd
put C:\downloads\customers.csv public_html/customers.csv

more info here : http://support.microsoft.com/kb/96269

more commands : http://www.nsftools.com/tips/MSFTP.htm#put

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