问题
Is it possible to transfer a file from local machine to a remote server if the php script (say using ftp functions ) resides on a remote server?. I heard it might take to set up the local machine as a FTP server and the local machine should have a static IP address.
I am looking for directions as to how to set up the local machine to be a ftp server?., or is there any other way with php other than the form file upload($_FILES) thing ?.
Would appreciate any help. Thanks!.
回答1:
FTP will work, but:
If the server and the client are on the same network, you can use a network share. Going this route, you can use the normal filesystem functions available in PHP (docs). Just use the network name and share path, flip the slashes to forward: "//servername/path/to/share" Here is a tutorial on setting up a network share, assuming Windows is the client OS.
If network share is out of the question, you can set up a local FTP server. Here is a Lifehacker article on how to set this up, assuming you have a Windows OS. There are similar tutorials for Mac and *nix, there are so many you'd have to try NOT to find them on Google. :) There are many other routes to set up the FTP server, it isn't that important which server you use, just make sure you aren't leaving yourself wide open to the internet. After you set up the local FTP server, use PHP's FTP functions to connect from the server to your local machine.
It really is a better route to use the network share if you can, but of course that isn't an option if the server is not in your local network.
回答2:
What is your local machine's operating system? If it's windows I would recommend FileZilla FTP Server. Here is a guide how to install and setup FileZilla FTP server.
来源:https://stackoverflow.com/questions/6387385/transfer-files-from-local-machine-to-remote-server-with-the-php-script-residing