Uploading files PHP uploading files on server side with Curl_init ()

Source: Internet
Author: User
Uploading files on the client is a common scenario that web development encounters. Don't repeat it here. Here we are going to elaborate on how to upload files to other servers on the service side.

This scenario is often encountered in a resource to synchronize multiple servers, such as a user uploading a picture from a server

Upload to another server.

In fact, uploading files on the server side is not a very difficult thing, as long as the PHP curl_init () can be done.

<?phprequire_once $_server [' document_root ']. ' /hosts.php ';//Ip$img_path of multiple servers = $_server [' document_root ']. ' /upload/test.jpg ';//image save path $file = Array ("Company_logo" = "@". $img _path);//file path, preceded by @, indicates file upload. foreach ($hosts as $host) {$curl = Curl_init ();//The URL that handles uploading a picture is the same as the principle that the client uploads the server curl_setopt ($curl, Curlopt_url, ' http://'. $host. ' /upload.php '), curl_setopt ($curl, curlopt_post,1), curl_setopt ($curl, Curlopt_postfields, $file); curl_setopt ($curl, Curlopt_returntransfer, 1); curl_setopt ($curl, curlopt_header,0); curl_setopt ($curl, Curlopt_ssl_verifypeer, FALSE); $result = curl_exec ($curl); $result get page Information curl_close ($curl);}? >
  • 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.