5492 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

I have a page that serves dynamic images to the logged in user. The images are created “on the fly” What I want to do is allow users to post this photo to their wall. Using the facebook sdk , I can happily do this by uploading, but no idea how to do it for images already on the web page .. so wondering, it cannot be that hard..can it ?

The code for the sdk is: ( trimmed )

//Obtain the access_token with publish_stream permission 
       if(empty($code)){ 
          $dialog_url= "http://www.facebook.com/dialog/oauth?" 
           . "client_id=" .  $app_id 
           . "&redirect_uri=" . urlencode( $post_login_url)
           .  "&scope=publish_stream";
          echo("<script>top.location.href='" . $dialog_url 
          . "'</script>");
         }
        else {
          $token_url="https://graph.facebook.com/oauth/access_token?" 
           . "client_id=" . $app_id 
           . "&redirect_uri=" . urlencode( $post_login_url)
           . "&client_secret=" . $app_secret
           . "&code=" . $code;
          $response = file_get_contents($token_url);
          $params = null;
          parse_str($response, $params);
          $access_token = $params['access_token'];

         // Show photo upload form to user and post to the Graph URL
         $graph_url= "https://graph.facebook.com/me/photos?" 
         . "access_token=" .$access_token;

         echo '';
         echo '<form enctype="multipart/form-data" action="'
         .$graph_url .' "method="POST">';
         echo 'Please choose a photo: ';
         echo '<input name="source" type="file"><br /><br />';
         echo 'Say something about this photo: ';
         echo '<input name="message" 
             type="text" value=""><br /><br />';
         echo '<input type="submit" value="Upload"/><br />';
         echo '</form>';
         echo '';

The scenario is such, we have say 12 images on the page. I want to add a “post to your timeline” button under each image, so that the logged in user can post that image to their timeline. On success, come back to page and perhaps post another etc.

So really looking for way to remove the
<input name="source" type="file">
part, and somehow replace with the url to the image.

Is this dooable ? It must be ..

5492 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

update: So I got chatting to some php gurus etc lol. They prescribe to the file_get_contents method. The issue being the , image is created in session and is not stored on the server.

So, wonder if anyone, knows some nifty jquery that …

Shows a download button for the image .. on success.. hides the download button and shows the upload form? I kind of know what to do, but not 100% on how to toggle event success .. if that makes sense.

However, wondered if I may be over complicating matters here, in so far as the file get contents, could that fetch a full URL or does it have to be path to image folder etc ?

1484 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+3 more
OriginalEXE says

You can fetch the image by url with file get contents, but it is better to use curl if it’s available on server (and it is on most of them).

I use this function in my plugin, it will first check for curl, and if that fails, it uses file get contents. It returns image as a file that you can later use for whatever you need.

function oe_gis_grab_the_file( $imgurl ) {
    if ( function_exists( 'curl_init' ) ) {
        return oe_gis_grab_the_file_curl( $imgurl );
    } elseif ( ini_get( 'allow_url_fopen' ) ) {
        return oe_gis_grab_the_file_fget( $imgurl );
    } else {
        return false;
    }
}

function oe_gis_grab_the_file_curl( $imgurl ) {
    $ch = curl_init();
    curl_setopt( $ch, CURLOPT_URL, $imgurl );
    curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
    $image = curl_exec( $ch );
    curl_close( $ch );
    return $image;
}

function oe_gis_grab_the_file_fget( $imgurl ) {
    $image = file_get_contents( $imgurl, false );
    return $image;
}
5492 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

Thankyou OriginalEXE

My lack of knowledge in this area is ridiculous. I appreciate your reply.

I think I may need to pay someone to create this for us lol. Would it be helpful if I posted an infographic?

5492 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

Nearest I have got is another piece of hijacked code, which was posted on stack.

$file= 'http://www.ourwebsite.com/facebook/images/t/watermark.php?file=1.gif';
$args = array(
   'message' => 'Photo from application',
);
$args[basename($file)] = '@' . realpath($file);
$ch = curl_init();
$url = 'http://graph.facebook.com/'.$album_id.'/photos?access_token='.$access_token;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $args);
$data = curl_exec($ch);
//returns the photo id
print_r(json_decode($data,true));

However I have no idea how to integrate that with the original code I posted, so that it adds the $file within the form, for submission to users album.

Added info

Our php coder has decided to show his face, will get him to look into it. If I get a fix, will post our code :)
160 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Interviewed on an Envato blog
  • Had an item featured in an Envato Bundle
+6 more
jordie says

Hey some of my apps deal with the facebook api. Message me if you still need help with it. :)

5492 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Located in Australia
  • Has sold $1,000+ on Envato Market
+4 more
Australia says

Hey some of my apps deal with the facebook api. Message me if you still need help with it. :)

G’day Jordie, thanks.

The issue, is more a html/php issue regarding the pushing of an image to an album rather than uploading an image to an album. Which is pretty easy to accomplish, the hard part is seemingly the posting of an image ( that has been created dynamically )

In fact, I reckon if anyone wanted to play with the code, and release a script on codecanyon this is seemingly something much needed.

For example, a user has a gallery on their website. The method I put in my first post, if coded well would allow site visitors to post that image to their own timeline, not the normal fetch thumbnail type of script, or upload an image type of script.

Virally, its a must have , hence we are pushing it. With over 26,000 users logged on our systems, and approx 5 million already uploaded images, its an ideal opportunity for us to allow our userbase to push an image from us to their own albums, ..

... Our coder is working his way thru it, for our usage. But it is something I reckon an accomplished author on here could and would make gazillions of sales !

160 posts
  • Has referred 50+ members
  • Has sold $10,000+ on Envato Market
  • Interviewed on an Envato blog
  • Had an item featured in an Envato Bundle
+6 more
jordie says


Hey some of my apps deal with the facebook api. Message me if you still need help with it. :)

G’day Jordie, thanks.

The issue, is more a html/php issue regarding the pushing of an image to an album rather than uploading an image to an album. Which is pretty easy to accomplish, the hard part is seemingly the posting of an image ( that has been created dynamically )

In fact, I reckon if anyone wanted to play with the code, and release a script on codecanyon this is seemingly something much needed.

For example, a user has a gallery on their website. The method I put in my first post, if coded well would allow site visitors to post that image to their own timeline, not the normal fetch thumbnail type of script, or upload an image type of script.

Virally, its a must have , hence we are pushing it. With over 26,000 users logged on our systems, and approx 5 million already uploaded images, its an ideal opportunity for us to allow our userbase to push an image from us to their own albums, ..

... Our coder is working his way thru it, for our usage. But it is something I reckon an accomplished author on here could and would make gazillions of sales !

Thanks for the idea :) I hope you get it solved.

by
by
by
by
by
by