将图像从img标签的src上传到php [英] Uploading Image from src of img tag to php

查看:206
本文介绍了将图像从img标签的src上传到php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只想询问是否有办法从 src 上传< img> 标签 。 img 标签的 src 不是来自服务器,看起来像这样:

I just want to ask if there is a way to upload an image from src of <img> tag . The src of the img tag was not from the server and look like this one:

<img src="data:image/png;base64,iVBOR...52Eysdsadsa===" />

这是我从这个网站。

提前谢谢。

如果你想让我解释这个北斗星,请告诉我。谢谢

Let me know if you want me to explaine this dipper. Thank you

推荐答案

您可以将base64编码的字符串(src部分)上传到服务器并保存原样或将其转换为图像并将其另存为文件。

You can upload base64 encoded string(src part) to the server and save it as it is or convert it into an image and save it as a file.

上传base64编码图像:

获取图像的src属性并将其发布到服务器。

Get the src attribute of the image and post it to the server.

var base64image = $('#blah').attr('src');

将base64编码的字符串转换为图像

$img = $_POST['base64image'];
$img = str_replace('data:image/png;base64,', '', $img);
$img = str_replace(' ', '+', $img);
$data = base64_decode($img);
$file = 'image.png';
$success = file_put_contents($file, $data);

或者只是将上传的内容保存到您的数据库中,然后使用以下代码在您的数据库中呈现图像页面:

Or simply save the uploaded content into your database and later use the below code to render the image on your page:

echo '<img src="'. $img .'" />';

这篇关于将图像从img标签的src上传到php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆