Re: [0.2.1] xajax.ext.SWFupload *updated*

edrobinson wrote:

Hi All,

Where the !@#$ is the latest  SWF Upload plugin code?


I found a really simple upload that incorporates into my XAJAX pages very simply: … orial.html

The html goes in your html and the php page saves the uploaded file.

On returning to the html, if the upload was successful, I call my registered function in the
current page to process the uploaded file.

If there is much interest I'll post some code...


Thanks, but it is not compatible with XAJAX ! and is independent code!

Re: [0.2.1] xajax.ext.SWFupload *updated*

My "simple xajax file upload" is based on Max's ajax file upload

The following code is taken from a trucking freight load app that I have been working on...

The upload page submits to this php page.
It saves the uploaded file and enters its path
in a session variable.
It saves the uploaded file and returns a success or failurse indicater
to the calling page.

  This little gem does the file upload from the load page.
  The path to the uploaded file is written to a session
   // Edit upload location here
   $destination_path = './inbound_files/';;
   $result = 0;
   $target_path = $destination_path . basename( $_FILES['myfile']['name']);
   $_SESSION['uploaded_file'] = $target_path; //Save for importer
   if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
      $result = 1;
<script language="javascript" type="text/javascript">
//Reply to the stopUpload function of the main upload page.<?php echo $result; ?>);

This code is the main page. It implements xajax and Maxs ajax upload.

  This page demonstrates using Max's ajax file uploader.
//--------------------------- Page Setup Stuff -----------------------------------------
$xajax = new xajax();
$xajax->configure('javascript URI', 'xajax/');
//--------------------- Loads table updat functions -----------------------
//This function uses the just uploaded table information to update
//the main loads table. It has been stripped for this illustration.
function UpdateTruckloads()
  $resp = new xajaxResponse();
// ... process the uploaded fle.
  $resp->alert("Load table update updated $ct records.");
  return $resp;
//-----------------------------------Uploaded File Handlers -----------------------------------------

//Main function. Called from the browser.
//Handles the uploaded file.
//Stripped for this illustration
function LoadInbound()
    $resp = new xajaxResponse();
    //Access the import text file or puke.
    $fname = $_SESSION['uploaded_file'];
    @$hdl = fopen($fname,'r');
    if (!$hdl)
        $resp->alert("Unable to open ".$fname);
        return $resp;    
//  ...Load the uploaded file into temporary db table or whatever you need to do    

    //All done. Let the user know what happened.
    $resp->alert("$fname has been loaded. Loaded $recCt records.");
    //Load the temporary table into the working table.
    return $resp;
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "">
<?php $xajax->printJavascript(); ?>
<!-- Max's style sheet -->
<link href="./styles/style.css" rel="stylesheet" type="text/css" />
<script language="javascript" type="text/javascript">
<!-- Functions to handle uploads per Maxs ajax upload
function startUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'visible';
      document.getElementById('f1_upload_form').style.visibility = 'hidden';
      return true;

function stopUpload(success){
      var result = '';
      if (success == 1){
         result = 'The file was uploaded successfully!';
      else {
         result = 'There was an error during file upload!';
      document.getElementById('f1_upload_process').style.visibility = 'hidden';
      document.getElementById('f1_upload_form').style.visibility = 'visible';      
      //Do the xajax file load process if OK.
      if (success == 1)
      return true;   
<div id="wrapper" style="margin-top: 200px;">
<div id="content" >
<!-- This form sends to upload.php which saves the uploaded file 
     then calls stopUpload() above.
<form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >
<p id="f1_upload_process">Loading...<br/><img src="./images/loader.gif" /><br/></p>
<p id="f1_upload_form" align="center"><br/>
<input name="myfile" type="file" size="30" />
<input type="submit" name="submitBtn" class="sbtn" value="Upload" /></center>
 <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
<div id="results" name="results"></div>

So the cycle is
1. Submit the upload using traditional upload.
2. Receive the success/fail indication frpm the upload handler.
3. If succesful, call the registered xajax function to process the file.

Hope this helps...


If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: [0.2.1] xajax.ext.SWFupload *updated*

Is this demo working for someone?

I've tried with xp and w7 and I can´t load it.
Error on w7 when click in browse files (at … load.php):
Erro: uncaught exception: Error calling method on NPObject! [plugin exception: Error in Actionscript. Use a try/catch block to find error.].

Thank you.

Re: [0.2.1] xajax.ext.SWFupload *updated*

yeahhh... found it! not compatible with flash player v10 :\

Re: [0.2.1] xajax.ext.SWFupload *updated*

to get working with json and xml responses (since bet 0.6) you have to make an "switch"

look for this function in swfupload.xajax.js

swf.settings.upload_success_handler =  function ( oFile, response )
            var xx = xajax;
            var xt =;
            var xcb = xx.callback;
            var gcb =;
            var lcb = oRequest.callback;

            var oRet = oRequest.returnValue;

            var FileId = swf.customSettings.currentFile;
            if ( 'function' == typeof this.old_upload_success_handler ) this.old_upload_success_handler( oFile );
            xcb.execute( [gcb, lcb], 'onSuccess', oRequest );
            var seq = 0;
            if ( response )
                /* init both handlers */
                var responseJSON = null;
                var responseXML = null;
                    var responseJSON = JSON.parse( response );
                catch ( ex )
                        var responseXML = ( new DOMParser() ).parseFromString( response, "text/xml" );
                    catch( ex2 )

                /* check for json response is usable */
                if ( ( null !==  responseJSON )  && ( 'object' == typeof responseJSON ) && ( 'object' == typeof responseJSON.xjxobj ) )
                    oRet = xt.json.processFragment( responseJSON, seq, oRet, oRequest );
                    /* or we have an xml based response */
                    var child = responseXML.documentElement.firstChild;
                    oRet = xt.xml.processFragment( child, seq, oRet, oRequest );