Home >Backend Development >PHP Tutorial >How to upload files to remote server in php
Sometimes in order to achieve load or other reasons, we need to place the uploaded files on other servers. Since I am not familiar with the tools on the server, I only start with the PHP program and use PHP's ftp or curl. To upload files to a remote server
Of course, both methods need to upload to the current web server first, and then transfer to other servers
The first method is to upload to the remote server via ftp, which requires a remote The server's ftp IP address, ftp user and ftp password are in the directory location allowed by permissions
The ftp class provided by www.yawill.com is used. Please see the attachment for the specific usage of this class
[php]
require " ./ftp.class.php";
$a = "";//Local path
$b = "";//Remote file name
$ftp = new ClsFTP("username","password",'202.202 .202.202');//Modify the settings by yourself
$ftp->cd('web');//Change to the directory. If you need to upload to the root directory, there is no 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 ordinary PHP uploads in processing uploads, but it needs to be prevented from malicious uploads by others. The source program is the work of other netizens. Unfortunately, the URL can no longer be opened
[php]
echo "< ;pre>";
print_r($_POST);
print_r($_FILES);
echo "";
//Here is the upload processing of the remote server
if(move_uploaded_file($_FILES['file1' ]['tmp_name'][1],'./test.txt')){
echo 'ok';
}
?>
[/php]