$_GET Fotonaam werkt niet?

Hallo,
Ik heb een raar probleem.
Als ik de foto naam direct in de PHP code schrijf dan werkt de upload prima.
Maar als ik de naam via $_GET aan de string toevoeg dan werkt het niet.
De uitvoer in HTML ziet er het zelfde uit. Maar de upload naar facebook werkt niet?
Aanroep: www.website.n//event1/upload?photo=123456.jpg
De Code die werkt:

[php]$photo_url = “http://website.nl/event1/pictures/123456.jpg”;
[/PHP]
En deze photoName via $_GET dus niet
[PHP]
$photo_url = “http://website.nl/event1/pictures/” .photoName;
[/php]
[php]

<?php $photoName = ''; //check what photo we are looking for if(isset($_GET['photo'])){ $photoName = $_GET['photo']; } ?> <?php $app_id = "**************"; $app_secret = "#############"; //Take NOTE: this must include http:// //ex. http://sharefavoritebibleverses.com/fb_connect.php $post_login_url = "http://website.nl/event1/upload.php"; //Take NOTE: this must include http:// $photo_url = "http://website.nl/event1/pictures/123456.jpg"; //you can add link to your image caption, but you can't use this tag visit my link $photo_caption = "Voor meer foto's kijk op http://website.nl/event1"; $code = $_REQUEST["code"]; //Obtain the access_token with publish_stream permission if (!$code) { $dialog_url= "http://www.facebook.com/dialog/oauth?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode( $post_login_url) . "&scope=publish_stream"; echo(""); } else { $token_url="https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&redirect_uri=" . urlencode( $post_login_url) . "&code=" . $code; $response = file_get_contents($token_url); $params = null; parse_str($response, $params); $access_token = $params['access_token']; // POST to Graph API endpoint to upload photos $graph_url= "https://graph.facebook.com/me/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode($photo_caption) . "&method=POST" . "&access_token=" .$access_token; echo ''; //echo file_get_contents($graph_url); $ok = file_get_contents($graph_url); if($ok) echo''; echo ''; } ?>

[/php]
En de code die niet werkt:
[php]

<?php $photoName = ''; //check what photo we are looking for if(isset($_GET['photo'])){ $photoName = $_GET['photo']; } ?> <?php $app_id = "**************"; $app_secret = "#############"; //Take NOTE: this must include http:// //ex. http://sharefavoritebibleverses.com/fb_connect.php $post_login_url = "http://website.nl/event1/upload.php"; //Take NOTE: this must include http:// $photo_url = "http://website.nl/event1/" .$photoName; //you can add link to your image caption, but you can't use this tag visit my link $photo_caption = "Voor meer foto's kijk op http://website.nl/event1"; $code = $_REQUEST["code"]; //Obtain the access_token with publish_stream permission if (!$code) { $dialog_url= "http://www.facebook.com/dialog/oauth?" . "client_id=" . $app_id . "&redirect_uri=" . urlencode( $post_login_url) . "&scope=publish_stream"; echo(""); } else { $token_url="https://graph.facebook.com/oauth/access_token?" . "client_id=" . $app_id . "&client_secret=" . $app_secret . "&redirect_uri=" . urlencode( $post_login_url) . "&code=" . $code; $response = file_get_contents($token_url); $params = null; parse_str($response, $params); $access_token = $params['access_token']; // POST to Graph API endpoint to upload photos $graph_url= "https://graph.facebook.com/me/photos?" . "url=" . urlencode($photo_url) . "&message=" . urlencode($photo_caption) . "&method=POST" . "&access_token=" .$access_token; echo ''; //echo file_get_contents($graph_url); $ok = file_get_contents($graph_url); if($ok) echo''; echo ''; } ?>

[/php]

Iemand idee?
Thanks

Henk,
Most of us here speak English. Can you please translate the problem into english? Thanks!

Ik heb het vertaald. ( Google) Sorry.
Bedankt voor de tip.
Groet Henk

I have translated. Sorry.
Thanks for the tip.
regards Henk

Well, first, thanks for the translation. I tried to translate this in Google’s translator, but, it did not work for me.

First, you should de-bug the code. Perhaps you are not receiving the photo’s name correctly. So, where you had the code to get the photo’s name:
[php]
$photoName = ‘’;
//check what photo we are looking for
if(isset($_GET[‘photo’])){
$photoName = $_GET[‘photo’];
}
[/php]
To debug it, try this:
[php]
$photoName = ‘’;
//check what photo we are looking for
if(isset($_GET[‘photo’])){
$photoName = $_GET[‘photo’];
}
die($photoName);
[/php]
What this will do is kill the program after it gets the photo’s name and display it to you.
Then, you can test the code selecting the photo you want to upload and see if the name matches.
If it does NOT match, then your form is not correct and you need to check the spelling of your form field for the photo’s name. Sometimes it is the caps uses. ( $_GET[‘photo’] is NOT the same as $_GET[‘Photo’] )
If you are receiving the correct name for the photo, you should check the code you posted. I noted that you close the BODY and the HTML in the middle of the page and you have ECHO’s after closing the page. This usually means that everything after closing the BODY/HTML is NOT displayed to the browser. One way to check that is to right-click on the page displayed after the PHP has been executed and select VIEW-SOURCE and check to see if your form is correctly displayed and that nothing is after the closing of the BODY and HTML. ( /body /html )

Hope this helps, let us know if you still have further problems! Good luck…

Thanks for your response.
I have tested, see code.
Output is the same in both.
Maybe its in $_GET ??
The GET variables are passed through urldecode().

Thanks and Regards Henk

[php]

<?php $photoName = ''; //check what photo we are looking for if(isset($_GET['photo'])){ $photoName = $_GET['photo']; } $encphotoName = urlencode($photoname); $phototest = "http://neton.nl/event1/pictures/205300.jpg"; //Take NOTE: this must include http:// $photo_url = "http://neton.nl/event1/pictures/" . $photoName; //you can add link to your image caption, but you can't use this tag visit my link $picname = urlencode($photo_url); $testname = urlencode($phototest); echo $photo_url; echo "
"; echo $picname; echo "
"; echo $testname; echo "
"; echo $phototest; echo "
"; echo $encphotoName; ?>

[/php]

Please post the results of the last post. I mean, show us the results of the output from the last post.
Or, even better, try this version of the last debug test:
[php]
$photoName = ‘’;

//check what photo we are looking for
if(isset($_GET['photo'])){
	$photoName = $_GET['photo'];
}
   echo "GET results=" . $photoName . "<br />";

$encphotoName = urlencode($photoname);
echo "encphotoName=" . $encphotoName . "<br />";

$phototest = "http://neton.nl/event1/pictures/205300.jpg";
echo "phototest=" . $phototest . "<br />";

//Take NOTE: this must include http://
$photo_url = "http://neton.nl/event1/pictures/" . $photoName;
echo "photo-url=". $photo_url . "<br />";
//you can add link to your image caption, but you can't use this tag <a href='http://link.com' >visit my link</a>

$picname = urlencode($photo_url);
echo "picname=" . $picname . "<br />";

$testname = urlencode($phototest);
echo "testname=" . $phototest;

[/php]
This is a minor change of your last posted code. It just adds the names of the variables so that you can see where the list of items break. Run this and post the results to us if you can not see what is wrong with it.
My guess is that one of the lines is breaking the results sent to it. This way it should show you exactly where it is breaking. Let us know…

Thanks for the help.
Here is the result of the above code.
gr Henk
On browser
www.website.nl/test.php?photo=205300.jpg
Result:

GET results=205300.jpg
encphotoName=
phototest=http://neton.nl/event1/pictures/205300.jpg
photo-url=http://neton.nl/event1/pictures/205300.jpg
picname=http%3A%2F%2Fneton.nl%2Fevent1%2Fpictures%2F205300.jpg
testname=http://neton.nl/event1/pictures/205300.jpg-------------------------------------------------------------------------------------

Well, other than a missed spelled encphotoName variable in our debugging code, it looks correct!

So, I went back to your original code and noticed you compare for empty $code variable in a different way that Facebook’s sample code does. Your code uses:
if (!$code)
Facebook’s sample uses:
if(empty($code)){

There is a minor difference in this. The first (your’s) check if the $code if false not empty. So, perhaps that might be the problem. Try changing that line and let me know.

This is where I read about how to set up the Facebook posts:
https://developers.facebook.com/blog/post/498/

This is where I read about the empty differences:
http://techtalk.virendrachandak.com/php-isset-vs-empty-vs-is_null/

Sponsor our Newsletter | Privacy Policy | Terms of Service