Sqlite-php reads remote images and saves them locally

Source: Internet
Author: User
{Code...} cannot be saved when the code above is inserted.
$ Handle = fopen ('HTTP: //... image address ', 'R'); $ content = ''; while (! Feof ($ handle) {$ content. = fread ($ handle, 8080);} fclose ($ handle); $ SQL = "INSERT INTO chat_msg (data) VALUES ('$ content ')";

The preceding Code cannot be saved during insert.

Reply content:
$ Handle = fopen ('HTTP: //... image address ', 'R'); $ content = ''; while (! Feof ($ handle) {$ content. = fread ($ handle, 8080);} fclose ($ handle); $ SQL = "INSERT INTO chat_msg (data) VALUES ('$ content ')";

The preceding Code cannot be saved during insert.

Are you sure you want to save it as base64 .....
A local folder should exist.
Directly use write

Why do we need to save images without addresses?

Binary Storage

Maybe you$contentThe size exceedsdataSize of field settings (or default)

Isn't all the images stored in the database store an image address ???

According to the code above, $ content is a binary file, and the strlen length is estimated to exceed 20 thousand. It is estimated that it exceeds the limit for inserting fields in your database.
I think you should first download and save the image to your local machine, and the database only needs to store the image path. At present, you have not seen the practice of directly storing the file in data.

I wiped it. I have to say that it is SB.
Please don't get angry. Let me hear it.

$ Data = file_get_contents ('image URL '); file_put_contents ('image storage path and filename'); // For example, file_put_contents ('. /download/test.jpg ', $ data); // then, the database can store the image storage address, for example: $ SQL = "INSERT INTO chat_msg (data) VALUES ('Download/test.jpg ')";

Of course, each file name stores a different file name. If you want to name it yourself, I will not explain it more.

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.