How PHP uploads files to a remote server

Source: Internet
Author: User
Sometimes in order to achieve the load or other reasons, we need to put the uploaded files on the other server, because I am not familiar with the server tools, so only from the PHP program, through PHP FTP or curl to implement the upload file to the remote server

Of course, both of these methods need to be uploaded to the current Web server before being transferred to another server

The first method is to upload FTP to the remote server, which requires a remote server FTP IP address FTP user and FTP password has permission allowed directory location
Using the FTP class provided by www.yawill.com, please see the attachment for the specific use of this class
[PHP]
<?php
Require "./ftp.class.php";
$a = "";//local Path
$b = "";//remote file filename
$ftp = new Clsftp ("username", "password", ' 202.202.202.202 ');//Modify Settings yourself
$ftp->cd (' web ');//change to the directory, if you need to upload to the root directory you don't have to change it.
$ftp->put ($b, $a. " /". $b);//put file
$ftp->close ();
?>
[/php]


2. Another method is to use curl to submit
This in the process of uploading with ordinary PHP upload is not much different, but need to prevent others malicious upload, the source program is the work of other netizens, unfortunately the Web site can not be opened
[PHP]
<?php
echo "<pre>";
Print_r ($_post);
Print_r ($_files);
echo "</pre>";
This is the upload process for 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.