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

edrobinson wrote:

Hi All,

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

Edit:

I found a really simple upload that incorporates into my XAJAX pages very simply:

http://www.ajaxf1.com/tutorial/ajax-fil … 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...

Ed

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 http://www.ajaxf1.com/product/ajax-file-upload.html.

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.

<?php
/*
  This little gem does the file upload from the load page.
  The path to the uploaded file is written to a session
  variable.
*/
   session_start();
   // 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;
   }
   sleep(1);
?>
<script language="javascript" type="text/javascript">
//Reply to the stopUpload function of the main upload page.
window.top.window.stopUpload(<?php echo $result; ?>);
</script>   

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

<?php 
/*
  This page demonstrates using Max's ajax file uploader.
*/
ob_start();
session_start();
//--------------------------- Page Setup Stuff -----------------------------------------
include_once("xajax/xajax_core/xajax.inc.php");
$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.
  $resp->loadCommands(UpdateTruckLoads());
    return $resp;
}        
//$xajax->configure('debug',true);
$xajax->register(XAJAX_FUNCTION,'LoadInbound');
$xajax->processRequest();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<?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';      
      alert(result);
      //Do the xajax file load process if OK.
      if (success == 1)
        xajax_LoadInbound();
      return true;   
}
//-->
</script>   
</head>
<body>
<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/>
<label>File:</label> 
<input name="myfile" type="file" size="30" />
<center>
<input type="submit" name="submitBtn" class="sbtn" value="Upload" /></center>
</p>
<br/> 
 <iframe id="upload_target" name="upload_target" src="#" style="width:0;height:0;border:0px solid #fff;"></iframe>
 </form>
<div id="results" name="results"></div>
</div>
</div>
</body>
</html>

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...

Ed

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 http://www.xajaxproject.org/developer/q … 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
xajax.ext.SWFupload.request.submitRequest

swf.settings.upload_success_handler =  function ( oFile, response )
        {
            var xx = xajax;
            var xt = xx.tools;
            var xcb = xx.callback;
            var gcb = xcb.global;
            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;
                try
                {
                    var responseJSON = JSON.parse( response );
                }
                catch ( ex )
                {
                    try
                    {
                        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 ) )
                {
                    oRequest.status.onProcessing();
                    oRet = xt.json.processFragment( responseJSON, seq, oRet, oRequest );
                }
                else
                {
                    /* or we have an xml based response */
                    oRequest.status.onProcessing();
                    var child = responseXML.documentElement.firstChild;
                    oRet = xt.xml.processFragment( child, seq, oRet, oRequest );
                }

            }