Access files in remote computer with php - php

I need to create an application using php which is hosted in a server and need to communicate with a csv file located in clients local machine. Is there any way we could do this ? How can I connect to a remote csv file ? Is this possible ?

Server machine accessing a csv file directly from a client machine is not a good idea. It's a security threat indeed. Consider you are navigating some website and it's server is able to access your computer's file system!!!
There are various alternatives to achieve this, some of these might be:
Make the user upload csv files to server in order to make it
available to the server application
If the client and server are in the same network, then share the
folder on client machine to make it accessible from the server
etc... I would have preferred the first option as mentioned above.

As #AnthonyB mentioned in comment under your question, server can't directly call client, and that is true. Server is called "server" as it serves requests from the client.
To be able to give away files to remote requests, your client needs its own server application, like Apache HTTPD for example.
In case if you need continuously request client's server to collect files with your PHP server, what you are looking for called "worker". One of AWS tools called Elastic Beanstalk offers possibility to choose a server or a worker application during start up wizard for PHP. It is pretty straight forward and easy to use.
Please note, that your client must have dedicated IP address or use Dynamic DNS approach by pushing its IP to a DB (or directly to a server) where worker will take it from.
If you don't need dedicated worker, you can configure CRON JOB to send requests to clients server applications.
IMHO, all that scenario worth it only if you are building corporate grade application. In most cases (and if you do REALLY need to collect files from clients) you have to install Apache + PHP server on the client side and make this guys to wait for request from YOUR remote php server. Without it, you can not get files from clients computers via browser without user input interactions. At least legally :)

Related

share data between server applications

I have 3 server that same server application is running on each of them. each installation of server app has its own configurations, data and settings.
other client users or client applications can connect to this servers and communicate with them.
this servers are in different places.
this application are created by PHP and servers are ubuntu servers, each server has its own static IP.
but now i need to share some data between this server applications. for example server A needs to access to information of server B's customers. or main admin of system want to see some information of server C. other scenario may be back up/sync. each server with 4th server with special application.
what is the best and more secure way to share some data between server applications? for example application A on server A needs some data get from application B on server B, or send some data to it.
There are several ways to do this, and it depends on if your goal is to send data synchronously or asynchronously.
If you want to send data synchronously (that is, send data, and wait for a response before proceeding to whatever the next step), use HTTPS.
If you want to send data asynchronously (that is, send data, then go off and do something else while the response can come back at any time), use XMPPS.
Both run over SSL, so that will handle the security side of things. Both HTTP and XMPP services are plentiful, so building the scripts to use these services for communication would be relatively straight-forward.

Auto discover a web server hosting PHP script

Having a simple PHP script running on a web server in my local network, how can I auto discover this script (or better the server hosting the script) using an external client (e.g., an Android app).
I am aware that this will not be possible with a pure PHP script hosted on a web server. I need to bind a socket to the broadcast address 255.255.255.255 or some multicast address.
Maybe a python script could do, e.g., http://stuvel.eu/blog/186/start-xbmc-from-remote
Apache ZooKeeper seems interesting but too big and complicated at the same time.
What other options are their? Does some of the "big" web servers provide some kind of easy to use service discovery?

File sending from browser to a server which is not a web server

I want to send a file from my browser to a server which is not the server on which the site is hosted.The problem is the another server is not a web server.
Is it programmatically possible to send a file to different server without the involvement of host server? I do not want copy of the file I am uploading on my hosting server.
Sorry for not being clear on the first go. I hope this makes sense.
Note: I have the IP address of server. Implementation has to be done in a secure way.
Create a signed application to handle the upload.
One of the fundamental rules of browser sandboxing is that you don't let the browser communicate to a server other than the one which provided the website. This has been a rule for quite some time, and is done for security reasons.
The only way I know of to bypass this restriction is to use a signed application. This is possible in several languages including at least Flash and Java. Once you've signed your application with an authoritative source, then you can specify that your application is known to communicate with a third-party server and should be trusted to do so. The process of doing this will be different depending on the technology you choose.
The server to which you are sending the file needs to allow some sort of protocol in order to accept the file. You do not specify what that is, but these languages should be more than sufficient to implement whatever you need.
given that you have the necessary authentication of the secondary server you can
i'll explain using ftp, but there can be other socket related ways
1) upload the file to your server as usual, using $_FILE
2) use the ftp class in php to transfer the file to the remote host
Thanks all for valuable suggestions. I am opting for bit weird way but it seems the only feasible solution considering the current requirements of the project.
I am planning to install lite version of web server and php on the external server which can accept uploaded files through browser.
Our team has worked out this is the best solution we can consider as of now.
Thanks again to all for their suggestions.
This is done all the time with Firefox plugins, (youtube etc.). Does it have to be driven from your page source ? How stealthily do you want to do this ?
The other server should use a common protocol, SSH or ftp or NFS or CIFS.
In any case the user is going to have to agree with the plugin or the applet or a third party service (think punkbuster) running in the background.
BF4 runs in a browser window via a plugin and routinely sends data to servers other than the game server.

How to communicate FTP transfer with standalone PHP Server?

I have a Ubuntu Server on which I have my Apache and FTP server (I am using Proftpd server). I have a small PHP CMS and for database I am using MySQL server. This was my server side environment. Now on client side I have a C# ftp client which I use to download the file from FTP server. Also, this C# client communicates with my PHP CMS.
So in short there are two communications occurs at a time
1. C# client and FTP server for file transfer.
2. C# client and PHP CMS for some other work.
So, now what I want is real time progress (progress bar) of my ftp transfer on one of my CMS webpage.
Obviously one of thing I can do is that I can tell my C# client to upload it's download progress to PHP server using some web service or web socket and then I can show the progress of ftp transfer(basically progress of downloading of C# client).
But before doing this I just want to know that is it possible for my PHP server to check what FTP server is doing. Since, no communication occurs between them I don't know how to accomplish it? I have a MySQL server and I know that proftp can communicate with MySQL server and it has some predefined table in which I can store whatever is ftp server doing. But will it possible to use it to show a real time progress? Is their any other technique to do this or will I have to force my C# client to do it?
From what you say, you have no need to talk to the FTP server at all (except to download the file, of course). Your FTP client could upload the FTP transfer status to a Web socket (and why could it not display it directly?), there to be recovered by the CMS and shown in the page. By using sessions, you do not even need to actively save that information anywhere, provided the Web socket call properly initializes the session cookies.
In the FTP client download callback function just add a call to send the progress status to the server. There, a scriptlet will save it into, say, $_SESSION['download_status']. An AJAX call on the CMS page can then retrieve it and display it periodically.
Don't forget to also upload FTP session and exception status (transfer interrupted, etc.).

What does PHP do when calling a URL located on the same Apache server?

I have two PHP applications on the same Apache server. At some point, application A needs to call a URL on application B.
So let's say a script located at http://somedomain.com/app1/action need to download http://somedomain.com/app2/action using file_get_contents() (the domain is the same for both applications)
I was wondering how does PHP handle this? Is the request going through the whole internet, as if it was a call to an external URL? Or is it somehow optimizing it and accessing the application on the server directly?
I think it depends from your DNS resolution and is not related to PHP.
If your network is properly configured, you should be able to access the site on your local network even by calling the public url.
To be sure about your request not leaving the server, you could use the localhost ( or 127.0.0.1 ) address. You can also use the local ip address to access it over the local network.
It uses the whole TCP/IP stack of the operating system, if that's what you want to know.
If it's in the same server, it wouldn't have to resolve the DNS name if you use 127.0.0.1 instead of somedomainname.com.
Usually request do not "go out" of your server, so application B is accessed quicly by application A.
Requests can "go out" in the wild and then being routed back to your server (and that's not so good for performance) if your server DNS are not configured well (pratically, your server can't recognize itself as somedomain.com).
The whole internet is big. But it would unlikely leave the server, depending on the network layout.
The request goes through every server between the source and the destination. Since they are the same, that is no servers.

Categories