totallyNotLizards
totallyNotLizards

Reputation: 8569

Can I read a local image with PHP, then post the image data as a multipart form request

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

Upvotes: 0

Views: 201

Answers (2)

Ranty
Ranty

Reputation: 3362

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.

Upvotes: 1

Christian Kuetbach
Christian Kuetbach

Reputation: 16060

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.

Upvotes: 1

Related Questions