Upload files PHP uploads files on the server with curl_init ()

Source: Internet
Author: User
Uploading files on the client is a common scenario for Web development. I will not go into details here. Here we will elaborate on how to upload files to other servers on the server. This scenario is often used to synchronize resources on multiple servers. for example, you need to upload images uploaded by users from one server to another. In fact, uploading files on the server is not very difficult, as long as you use PHP curl_init. & Amp; lt... Upload files on the client, which is a common scenario for Web development. I will not go into details here. Here we will elaborate on how to upload files to other servers on the server.

This scenario is often used to synchronize resources on multiple servers. for example, you need to extract images uploaded by users from a server.

Upload to another server.

In fact, uploading files on the server is not very difficult, as long as you use PHP curl_init.

 '@'. $ Img_path); // file path. add @ to the front to indicate that the file is uploaded. foreach ($ hosts as $ host) {$ curl = curl_init (); // process the URL of the uploaded image. The principle is the same as that of the client uploading to 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, expires, 1); curl_setopt ($ curl, CURLOPT_HEADER, 0); curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, FALSE); $ result = curl_exe C ($ curl); // $ result obtain the 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.