+2  A: 

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.

Lucanos
I just tried that. I changed the form to the way you have it, but the same problem exists in Internet Explorer and now in Opera. I need it to at least work properly in Internet Explorer. Anymore ideas?
Zachary Brown
Just tested it in Chrome and it does the same thing. Now, all the browsers do it. I would like to know what it is doing and why.
Zachary Brown
I am unsure whether you are saying that my suggestion A) fixed the problem for all, B) fixed the problem for some, or C) the problem now affects all browsers. If you can re-comment with details, that would be great.
Lucanos
In the meanwhile, I would strongly suggest that you clean up the markup of your page (the one seen in the `iframe`. IE is notorious for being extremely unforgiving if it is given non-standard markup, and that may be contributing to your problems here. Having looked at your markup, which seems to use alot if un-necessary divs, including one which contains the start of the `form`, which then ends in a separate (and not directly connected) div further down the page, you're just asking for trouble. Maybe even try it with a stripped-down, basic version of the form?
Lucanos
Sorry. The problem now effects all browsers, unfortunately. I changed the target back to _self so it at least works in Opera, but I really need to get it working in Internet Explorer. I think the problem is that the form, when submitted redirects the entire page, instead of just the iframe. Could be something deeper, but I'm not sure.
Zachary Brown
I have just replicated a problem in IE8, where a submission of the form sent me to **http://majik.zbrowntechnology.info/home.php?Fatal** I would suggest that this is probably a PHP coding error on your server redirecting the user to this page, and possibly doing something else screwy. Revisit all your code, check the HTML markup for validity and the PHP for logic errors/redirections, etc.
Lucanos
I posted the code for the upload script above. Couldn't find anything, but maybe you can?
Zachary Brown
Recommended testing: 1) Replace the current `upload.php` script with one which contains nothing but a `header('Location: test.htm');` call. 2) Create a basic, easily recognised, file in `test.htm`. Load your application and see if the redirect affects things. If not, then the problem lies elsewhere.Regarding credits - don't worry about crediting me directly - If you want to credit StackOverflow and link to it, feel free. Happy to share the public eye.
Lucanos
Awesome! I did as you suggested in Test 1, and everything worked exactly as it was supposed to! So, this brings me to ask... what is wrong with the upload script? ( P.S. I would be more than happy to credit Stackoverflow. )
Zachary Brown
It has something to do with actually moving the file to the upload directory. I'll post it as a new question and offer a bounty for working code. I'll add you, Lucanos, and Stackoverflow to the credits page after the app problems have been corrected.
Zachary Brown
Figured out what the issue was! It was in the bit a PHP at the top of the page! I used require_login(), so it checked the login page to see if the user was logged in to the app, the redirected back to the last page when the user was. This is fine, but the request was made from a page in the iframe! Anyway, I added ?user="USER ID HERE" to the end of each URL so that each page has direct access to the user ID and doesn't have to get it from Facebook more than once! Thanks to everyone that helped. I'll give Lucanos the credit as he helped with all the testing and provided solution after solution
Zachary Brown
+1  A: 

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.

Lucanos
Ok, I ran the script you wrote for me, thanks by the way. It did detect errors and displayed the following: 1). No Files - Empty 2). Filename does not look like a JPEG and finally 3). Filetype is What does this mean, an error with the form realizing that a file has been chosen?
Zachary Brown
I made a typo in the above - had the logic reversed for the `empty()` check - I have corrected it. It sounds like you tried to upload a non-jpeg file.
Lucanos
Ok, corrected that. Now it works fine in Opera again, but it fails to work in Internet Explorer. It is doing the same thing as when I originally posted this question. Only, now it is also displaying the same information I posted as a comment above.
Zachary Brown