How to upload files to a remote server using php

Source: Internet
Author: User
Sometimes, in order to achieve load or other reasons, we need to place the uploaded files on another server. because I am not familiar with the tools on the server, therefore, we only start with the php program and use the ftp or curl of php to upload files to the remote server.

Of course, both methods need to be uploaded to the current web server before being transferred to other servers.

The first method is to upload the file to the remote server through ftp, which requires the ftp IP address of the remote server. The ftp user and the Directory location permitted by the ftp password are required.
The ftp class provided by www.yawill.com is used. for details about how to use this class, see the attachment.
[Php]
Require "./ftp. class. php ";
$ A = ""; // Local path
$ B = ""; // remote file name
$ Ftp = new ClsFTP ("username", "password", '192. 202.202.202 '); // modify the settings
$ Ftp-> cd ('web'); // change to the directory. if you need to upload the file to the root directory, you do not need to change it.
$ Ftp-> put ($ B, $ a. "/". $ B); // put file
$ Ftp-> close ();
?>
[/Php]


2. Another method is to use curl to submit
This is not much different from normal php uploads in terms of processing uploads, but it is necessary to prevent malicious uploads by others. the source program is the work of other netizens. Unfortunately, the website cannot be opened.
[Php]
Echo"

";
Print_r ($ _ POST );
Print_r ($ _ FILES );
Echo"
";
// Upload process on the remote server
If (move_uploaded_file ($ _ FILES ['file1'] ['tmp _ name'] [1], './test.txt ')){
Echo 'OK ';
}
?>
[/Php]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.