View Full Version : Some help with POST method and forms

11-03-2010, 06:46 PM
Hi hope you are all well.

I am having some problems trying to install a picnik api edit facility and would greatly appreciate some help with my code. I am very new to coding of any kind so I apologise in advance for being a newb!

What I 'want' to happen:
user browse for photo
user clicks import
image sent to picnik for editing
user edits image
user clicks 'export'
edited image saved on mysite.com server (i.e. /customer pics)
customer returned to original upload url with small thumb of uploaded/edited pic/success message etc.

Where I have got so far:
user browse for photo
user clicks import
image sent to picnik for editing
user edits image
user clicks 'export'

from here I am struggling! When export is clicked, picnik redirects to original product/upload url(for customer to complete order). But no preview of edited image and no image is uploaded to '/customer_pics' folder. So I know I still have some work to do, but reading through picnik help is just confusing me even more!

I currently have the following code:

<form action="http://www.picnik.com/service/?_apikey='MYAPIKEY'&amp;_export=http%3A//www.MYWEBSITE.com/" enctype="multipart/form-data" method="POST"> <input name="_apikey" type="hidden" value="MYAPIKEY" />
<input name="_import" type="hidden" value="imagedata" />
<input name="imagedata" type="file" />
<input type="submit" value="Import!" />

I also have the following code saved in my '/customer_pics' folder as 'push.php', since I am using the push method. I am trying to work out how to use this to 1. Receive the data. 2. Process it (eg., save it somewhere). 3. Display a result page with thumb(eg., back to same url).

// PHP script to receive image data from Picnik via HTTP POST

// Make sure we've been sent an image. By default, the
// image data goes into the "file" field, but we could
// change that using the _export_field API parameter.
if (!isset($_FILES['file'])) {
echo "Sorry, no image data was sent.";

// retrieve the image's attributes from the $_FILES array
$image_tmp_filename = $_FILES['file']['tmp_name'];
$image_filename = $_FILES['file']['name'];

// Save the image to disk. It'll go into the same directory as
// this script. You'd probably want to put it somewhere else in the
// file system like a "/images" directory, or maybe even into a database.
// Make sure your web server has write access to the destination dir,
// or the call to file_put_contents isn't going to work.
$image_data = file_get_contents( $image_tmp_filename );

// Note: file_put_contents requires PHP 5. Use fopen/fwrite/fclose for earlier versions.
file_put_contents( $image_filename, $image_data );

// Display a result to let the user know what happened. You
// might need to be smarter about how the $image_link variable is
// built, depending on how your web server is set up.
$image_link = dirname($_SERVER['PHP_SELF']) . "/" . $image_filename;
echo "Your file was saved to $image_filename.<br/>";
echo "You can find it at this URL: <a href='$image_link'>$image_link</a><br/>";
echo "<img src='$image_link'>";

Any help, advice, pointers in the right direction would be greatly appreciated and thank you in advance for time and help offered.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum