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]
<?php require "./ftp.class.php"; $a = "";//本地路径 $b = "";//远程文件文件名 $ftp = new ClsFTP("username","password",'202.202.202.202');//自行修改设置 $ftp->cd('web');//更改到目录,如果你需要上传到根目录就不用改了 $ftp->put($b,$a."/".$b);//put file $ftp->close(); ?> [/php]
ftp upload source file And demo download
http://www.dayanmei.com/download.php?filename=ftpclass.rar
2. Another method is to use curl to submit
This is not much different from ordinary PHP upload in terms of upload processing , but we need to prevent others from uploading maliciously. The source program is the work of other netizens. Unfortunately, the URL can no longer be opened
[php]
<?php echo "<pre class="brush:php;toolbar:false">"; 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]
curl upload source file and demo download
http ://www.dayanmei.com/download.php?filename=curl_upload.rar

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

