sqlite-php read remote picture saved to local

Source: Internet
Author: User
$handle = fopen('http://...图片地址', 'r');$content = '';while(!feof($handle)){    $content .= fread($handle, 8080);}fclose($handle);$sql = "INSERT INTO chat_msg (data) VALUES('$content')";

The above code cannot be saved when you insert it.

Reply content:

$handle = fopen('http://...图片地址', 'r');$content = '';while(!feof($handle)){    $content .= fread($handle, 8080);}fclose($handle);$sql = "INSERT INTO chat_msg (data) VALUES('$content')";

The above code cannot be saved when you insert it.

Are you sure you want to save it as a base64 ...?
You said that there should be a folder in the local
Directly with Write

Why do you want to save the picture, not the address?

To use binary storage

Maybe your $content size exceeds the data size of the field setting (or default)

Database store pictures are not all stored a picture address???

According to the above code $content is a binary file, strlen length estimates are over 20,000, estimated beyond the limits of your database insert field.
I think you should be the first to save the picture to the local, the database as long as the image path is stored. I don't see the practice of putting files directly into the data at the moment.

I rub, you do this kind of writing I have to say very sb.
Please don't be angry, listen to me slowly.

$data = file_get_contents('图片网址');file_put_contents('图片存储的路径和文件名');// 如file_put_contents('./download/test.jpg',$data);//然后,数据库存储这个图片的存储地址就可以了,例如:$sql = "INSERT INTO chat_msg (data) VALUES('download/test.jpg')";

Of course, the file name of each store file name is not the same, you find a way to name it, I do not explain 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.