PHP Image Storage to server

Source: Internet
Author: User
How does the code write the image stored in PHP to the server?

  1. PHP files on the server;

  2. The picture URL is known;

Reply content:

How does the code write the image stored in PHP to the server?

  1. PHP files on the server;

  2. The picture URL is known;

The idea is to get the picture in the PHP code first and then store it locally on the server.

The code can be organized like this:

$url = 'http://pic22.nipic.com/20120627/7947919_114513420170_2.jpg';$img = '/tmp/bear.jpg';$pic = file_get_contents($url);file_put_contents($img, $pic);

You can also use curl, and then set CURLOPT_FILE the property to a local file.

A thought, download the URL address of the picture to local, and then upload to the remote server.

Direct copy

Usually when writing PHP, the image upload is the client's local file address, local address to a known URL address, write a script to upload directly

  • 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.