PHP Facebook App Help!
I wrote a Facebook app from PHP and HTML that work perfect in the Opera browser, but doesn't work in Internet Explorer or Google Chrome.
The page index of the app is at: http://apps.facebook.com/zbtmajik/
After you choose an image to upload and choose the 'Upload' button, it is supposed to redirect to http://majik.zbrowntechnology.info (inside the iframe ) and keeps redirecting to http://majik.zbrowntechnology.info/?auth_token=e0afbd3167ae943a94b41e940298f2d1&next=http%3A%2F%2Fmajik.zbrowntechnology.info%2Fupload.phpI think it might be an issue with the iframe since it seems like when I submit the form, it attempts to redirect the entire page instead of just what is in the iframe.
I have know idea what the problem is, but it is for work and I need to get it fixed. Any help would result in your name on a thank you page on the app!
_____ upload.php____________________________________________________________________ I was told that it may be the PHP code that processes the upload, so here it is:
<?php
include_once('facebook.php');
$appapikey = 'API KEY HERE';
$appsecret = 'SECRET KEY HERE';
$facebook = new Facebook($appapikey, $appsecret);
$fb_user = $facebook->require_login();
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
$filename = basename($_FILES['uploaded_file']['name']);
$ext = substr($filename, strrpos($filename, '.') + 1);
if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") &&
($_FILES["uploaded_file"]["size"] < 350000)) {
$newname = dirname(__FILE__).'/upload/zbt_'.$fb_user.'.jpg';
if ((move_uploaded_file($_FIL开发者_开发知识库ES['uploaded_file']['tmp_name'],$newname))) {
header("Location: http://majik.zbrowntechnology.info/display.php");
} else {
header("Location: home.php?Fatal");
}
} else {
header("Location: home.php?Fatal");
}
} else {
header("Location: home.php?Fatal");
}
?>
I have looked over it and can't seem to find anything, but I'm not a very strong PHP programmer either.
I looked over the code again in the PHP doc, and found that the problem lies on this line: if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {. Not sure exactly what it is though.
Change the target
attribute of the form
to "sourceframe" (the iframe
's name
value).
<form enctype="multipart/form-data" method="POST" action="http://majik.zbrowntechnology.info/upload.php" target="_self">
<input type="hidden" value="1000000" name="MAX_FILE_SIZE">
<input type="file" style="height: 70px; font-size: 20px;" size="50" accept="image/.jpg" id="file" name="uploaded_file">
</form>
becomes
<form enctype="multipart/form-data" method="POST" action="http://majik.zbrowntechnology.info/upload.php" target="sourceframe">
<input type="hidden" value="1000000" name="MAX_FILE_SIZE">
<input type="file" style="height: 70px; font-size: 20px;" size="50" accept="image/.jpg" id="file" name="uploaded_file">
</form>
This tested OK in FF3.6 & Chrome6.0
Also, as a side-note, the HTML markup of the page shown in the iframe is not the clearest - you may want to work on that at some stage as well.
I have looked at your PHP script in the question. As we have eliminated the redirect as the cause of the problem, let's look at the upload handler.
I have rewritten the script, and included a pile of debug messages, and I have also added a line which will delete an existing file if a user uploads a second one.
<?php
include_once( 'facebook.php' );
$appapikey = 'API KEY HERE';
$appsecret = 'SECRET KEY HERE';
$facebook = new Facebook( $appapikey , $appsecret );
$fb_user = $facebook->require_login();
if( empty( $_FILES['uploaded_file'] )
|| $_FILES['uploaded_file']['error']!=0
|| !preg_match( '/\.jpe?g$/i' , basename( $_FILES['uploaded_file']['name'] ) )
|| $_FILES['uploaded_file']['type']!='image/jpeg'
|| $_FILES['uploaded_file']['size']>350000 ){
/* DEBUG CODE - START */
echo '<h2>Error Detected</h2>';
echo '<ul>';
echo ( empty( $_FILES['uploaded_file'] )
? '<li>No Files - Empty</li>' : '' );
echo ( $_FILES['uploaded_file']['error']!=0
? '<li>Error '.implode(',',$_FILES['uploaded_file']['error']).'</li>' : '' );
echo ( !preg_match( '/\.jpe?g$/i' , basename( $_FILES['uploaded_file']['name'] ) )
? '<li>Filename does not look like a JPEG</li>' : '' );
echo ( $_FILES['uploaded_file']['type']!='image/jpeg'
? '<li>Filetype is '.$_FILES['uploaded_file']['type'].'</li>' : '' );
echo ( $_FILES['uploaded_file']['size']>350000
? '<li>Filesize is '.$_FILES['uploaded_file']['size'].'</li>' : '' );
echo '</ul>';
/* DEBUG CODE - END */
if( !headers_sent() )
header( 'Location: home.php?fatal' );
die();
}
$newname = dirname(__FILE__).'/upload/zbt_'.$fb_user.'.jpg';
if( file_exists( $newname ) ){
# User file already exists - Delete the Existing one.
unlink( $newname );
}
if( !move_uploaded_file( $_FILES['uploaded_file']['tmp_name'] , $newname ) ){
/* DEBUG CODE - START */
echo '<h2>Error Detected</h2>';
echo '<ul>';
echo '<li>Unable to Move File</li>';
echo '</ul>';
/* DEBUG CODE - END */
if( !headers_sent() )
header( 'Location: home.php?fatal' );
die();
}
header( 'Location: display.php' );
die();
If/when it works, remove anything between the /* DEBUG CODE - XXX */
sets.
精彩评论