我可以使用 PHP 读取本地图像,然后将图像数据作为多部分表单请求发布吗
如标题所示: 我正在使用 picnik API,想知道是否有一种方法可以以编程方式发送 picnik 图像数据,就像用户自己上传图像一样。
我正在考虑这样做,因为该网站是一个 CMS,并且我无法向 picnik 传递 URL 来获取图像,因为该网站需要登录。
本质上来说:
PHP 从磁盘加载图像,然后生成一个包含表单的页面,该表单中已经加载了该图像数据。单击提交按钮会将请求发送到 picnik,他们会获取图像。
这可能吗,或者有更好的方法吗?
As in title:
I'm playing with the picnik API and wondering if there is a way to programatically send picnik the image data as if the user uploaded the image themselves.
I'm looking at doing it this way because the site is a CMS and I can't pass picnik a URL to get the image as the site is behind a login.
So essentially:
PHP loads the image from the disk and then generates a page containing a form which has this image data loaded into it already. Clicking the submit button sends the request to picnik and they get the image.
Is this possible, or is there a better way?
Reference: http://www.picnik.com/info/api/tutorials/sending-images-in
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果图像未存储在服务器上,则无法执行此操作。由于沙箱安全模型。您无法通过 javascript 或 php 从客户端读取数据。
If the image isn't stored at the server, you cannot do this. Because of the sandbox security-model. You can't read data from a client via javascript or php.
如果我理解问题是正确的,换句话说,它如下:登录后的 CMS 用户无法将图像直接发送到 picnik,因为如果您将图像存储在您的服务器上,picnik 由于访问而无法读取它限制。
如果这是正确的,您可以伪造图像发送表单,如 picnik 手册中所述
案例 #3:使用 HTTP POST 发送图像数据
。您需要做的就是制作一个带有文件输入字段的表单。然后,用户将图像提交到您的 CMS,您可以使用curl post 请求立即将数据发送到 picnik,而不是将其存储在服务器上并将链接发送到 picnik。对于您的用户来说,看起来就像他将图像发布到您的 CMS 中一样。对于 picnik 来说,看起来就像用户向他们提交了图像。
If I understood the problem correct, in other words it is as follows: users of your CMS behind the login can't send images directly to picnik, because if you store the image at your server, picnik can't read it due to access restrictions.
If that's correct, you can fake the image sending form, described in picnik's manual as
Case #3: Sending image data with HTTP POST
. All you need to do is to make a form with file input field. Then user submits the image to your CMS and instead of storing it on the server and sending the link to picnik, you can just use a curl post request to send the data to picnik right away.For your user it will look like he posted the image to your CMS. For picnik it will look like the user submited the image to them.