Home > 类库下载 > PHP类库 > body text

How to upload files to remote server in php

高洛峰
Release: 2016-10-14 10:39:16
Original
1582 people have browsed it

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",&#39;202.202.202.202&#39;);//自行修改设置
$ftp->cd(&#39;web&#39;);//更改到目录,如果你需要上传到根目录就不用改了
$ftp->put($b,$a."/".$b);//put file
$ftp->close();
?>
[/php]
Copy after login

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 "
Copy after login
";

//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


source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!