?
Solved

Uploading Dynamic Photo to Facebook using the API?

Posted on 2010-11-27
8
Medium Priority
?
1,536 Views
Last Modified: 2013-11-19
Hi,

My App trying to uploading a dynamic photo (created by GD + pulling data from MySQL database) so the photos don't statically exist in the directory and for so I get this error :

Fatal error: Uncaught CurlException: 26: failed creating formpost data thrown in

Let's say I'm trying to upload www.mywebsite.com/223.jpg which is dynamic photo you can see it by checking this url directly or calling it as image but If I tried to use it in my Facebook App it wouldn't upload. If I downloaded to photo to my PC then uploaded to my ftp the App would upload it successfully. So I'm sure that my code is working just fine but the problem is with being Dynamic photo (doesn't actually exist in my website ftp).

Please let me know how can I solve this problem.

Code attached:

Thanks for your time.
$photo_details = array(
    'message'=> $message
);
$file = "$_GET[id].png";
$photo_details['image'] = '@/home/username/public_html/files/' . $file;
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

Open in new window

0
Comment
Question by:Dido123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34225441
Can you please show us a complete code segment that works, like one with an existing file?

CURL error #26 is pretty well understood to be a read error.
http://curl.haxx.se/mail/archive-2003-06/0121.html

Possibly the error arises because (1) the path to the dynamically generated photo is wrong or (2) the file permissions are too restrictive.

I'm also really unsure about this from line 4 of the post above: $file = "$_GET[id].png";

So my instant recommendation is to prepare each of your variables separately so you can visualize them.  Add var_dump($photo_details); after line 5 and see if you're getting the values you expect in that array.  Change line 6 to something more like what is in the code snippet.
// NOT THIS
$upload_photo = $facebook->api('/'.$album_uid.'/photos', 'post', $photo_details);

// INSTEAD THIS
$str = '/' . $album_uid . '/photos';
var_dump($str);
$upload_photo = $facebook->api($str, 'post', $photo_details);

Open in new window

0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34225477
Wow, it works and does not bark about anything, so long as the id= parameter is a string.

<?php // RAY_temp_dido123.php
error_reporting(E_ALL);
$file = "$_GET[id].png";
var_dump($file);

Barks about undefined index:
http://www.laprbass.com/RAY_temp_dido123.php

Reasonable output:
http://www.laprbass.com/RAY_temp_dido123.php?id=foo

Strange output:
http://www.laprbass.com/RAY_temp_dido123.php?id[]=foo

I think I would write that line more like this, but it's apparently OK for your app the way it is.
if (!empty($_GET['id']))
{
    $file = $_GET['id'] . '.png';
}
else
{
    $file = 'default.png';
}

Open in new window

0
 

Author Comment

by:Dido123
ID: 34227124
Ray, thanks for your input. I did tried my code and it works if I uploaded 123.png to my ftp. The problem is the photos created dynamically when you call it. So it's not statically found in the ftp. How can I bypass this problem. All I can think of is that the Facebook API needs to find the actual photo in the directory when it tries to upload it. Is there anything that can somehow create a temp photo so the API can find it then it would be deleted after the upload completed or at least something in this way?

Thanks again for your help.
0
2017 Webroot Threat Report

MSPs: Get the facts you need to protect your clients.
The 2017 Webroot Threat Report provides a uniquely insightful global view into the analysis and discoveries made by the Webroot® Threat Intelligence Platform to provide insights on key trends and risks as seen by our users.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34228483
Without seeing the code, all we would be doing is guessing.  Have you tried the visualization techniques I suggested above?

If your script creates a file and marks it with permissions that make it readable, CURL should be able to read the file.
0
 

Author Comment

by:Dido123
ID: 34244308
After a couple of days researching I came to conclusion that the problem is not in my code. The problem is code above can't read the image since it's dynamic image (requires running the php file which creates it first) so now my solution should be opening the dynamic image and presenting to the code above as static image so it can upload it. The problem is I can't even know where should I start to find my solution. Is fopen or fread might help here?

I really appreciate your help Ray.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 34244970
Let me say this again: "Without seeing the code, all we would be doing is guessing."

Show us how you create the dynamic image.  If you do the following things in order, it WILL work.

1. Create the image
2. Write the image to your server in the file system
3. Set the permissions on the file to allow read and execute.
4. Only after that, treat the file as a static image.

You may want a garbage collection routine just prior to #1 -- it would delete any files that are more than two days old.
0
 

Author Closing Comment

by:Dido123
ID: 34255109
Thank you. Problem solved. That's exactly what I did.

I created temp file for photos I want to upload then I added cron job to empty the temp folder once a day. Thanks again.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 34257979
Bingo!  Thanks for the points - glad it's pointed in the right direction, ~Ray
0

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question