Topic: xajax don't like a piece of php code (not evaluated, like skipped)

Hi all,
I have a big nasty problem. My script doesn't care about a function..

[code]<?
if (isset($_POST['PHPSESSID'])) {
    session_id($_POST['PHPSESSID']);
}
session_start();

ini_set("display_errors",1);
error_reporting(E_ALL ^E_NOTICE);

$core = '../xajax/xajax_core';
require_once $core . '/xajax.inc.php';

$xajax = new xajax();
require_once '../xajax/xajax_plugins/request/swfupload/swfupload.inc.php';
$xajax->configure("javascript URI","../xajax/");

$xajax->register(XAJAX_FUNCTION,"uploader",array("mode" => "'SWFupload'","SWFform" => "'upload_form'"));
$xajax->register(XAJAX_FUNCTION,"transform");
$xajax->register(XAJAX_FUNCTION,"destroyform");

$xajax->autoCompressJavaScript("../xajax/xajax_plugins/request/swfupload/swfupload.js",true);
$xajax->autoCompressJavaScript("../xajax/xajax_plugins/request/swfupload/swfupload.xajax.js",true);
$xajax->autoCompressJavaScript("../xajax/xajax_plugins/request/swfupload/swfupload.queue.js",true);

$xajax->processRequest();

function transform() {

    $objResponse = new xajaxResponse();
    $objResponse->clsSwfUpload->transForm('upload_form'
    ,array(
    "file_types" => "*.jpg;*.gif;*.png;"
    ,"file_types_description" => "Image Files or mp3"
    ,"file_size_limit" => "5 MB"
    ,"upload_complete_handler" => "fineFile"
    ,"post_params" => array(
    "PHPSESSID" => session_id()
    )
    , true
    )
    );


    return $objResponse;
}

function destroyform() {

    $objResponse = new xajaxResponse();
    $objResponse->clsSwfUpload->destroyForm('upload_form');

    return $objResponse;
}

function uploader($aFormValues) {
    $html = "";
    $objResponse = new xajaxResponse();
    $save_path = '/dati/httpdoc/gfinance/affiliati/tmp/';
    $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-';
    foreach ($_FILES as $key => $file) {
        $html .="
                <div style=\"border:1px solid #f0f0f0;background:#fff;padding:4px;margin-bottom:4px;\">
                    <div style=\"float:left;width:100px;\">Filename:</div>
                    <div style=\"float:left;\">".$_FILES[$key]['name']."</div>
                    <br style=\"clear:both;\" />
                    <div style=\"float:left;width:100px;\">Size:</div>
                    <div style=\"float:left;\">".$_FILES[$key]['size']."</div>
                    <br style=\"clear:both;\" />
                </div>
                "    ;
                $file_name = preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$key]['name']));
                $file_name .= $aFormValues['foo'];
                move_uploaded_file($_FILES[$key]["tmp_name"], $save_path.$file_name);
    }
    if ("" == $html) $html="empty queue";
    $objResponse->append("risposta","innerHTML",fine($aFormValues));
    return $objResponse;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>XAJAX UploadProgress Plugin</title>
    <?php $xajax->printJavaScript();?>
    <link rel="stylesheet" type="text/css" href="demo.css" />

        <script type="text/javascript">
    /* <![CDATA[ */
    function debugObj(elm) {
        xajax.$('results').innerHTML += "<hr />DEBUG:<hr /><br />";
        for (a in elm) {
            xajax.$('results').innerHTML += "<strong>"+a+":</strong> "+elm[a]+"<br />";
            if ("object" == typeof elm[a]) {
                for (b in elm[a]) {
                    xajax.$('results').innerHTML += "<div style=\"margin-left:20px;\"><strong>"+b+":</strong> "+elm[a][b]+"<br /></div>";
                }
            }
        }
    }
    /* ]]> */

    function fineFile(file,serverData){
    document.getElementById('results').innerHTML += "<div style=\"border:1px solid #f0f0f0;background:#fff;padding:4px;margin-bottom:4px;\"><div style=\"float:left;width:100px;\">Filename:</div><div style=\"float:left;\"><a href=\"tmp/" + file.name + "\" target=\"_blank\">" + file.name + "</a></div><br style=\"clear:both;\"><div style=\"float:left;width:100px;\">Size:</div><div style=\"float:left;\">Kb " + file.size/1000 + "</div><br style=\"clear:both;\"></div><br>";
    }

    </script>
</head>
<body onload="xajax_transform();">

    <h1>XAJAX SWFupload Plugin</h1>

    <div id="example">
        <h2>demo</h2>
        <form enctype="multipart/form-data" id="upload_form" name="upload_form" action="" onsubmit="return false;" method="post" >
           
            <div class="formLabel">test field:</div>
            <div class="formField">
                <input type="text" id="foofield" name="foo" value="bar" />
            </div>
            <div style="clear:both;" ></div>

            <div class="formLabel">Normal field 1:</div>
            <div class="formField">
                <input type="file" id="upFile_standard" name="upFile_standard" value="" />            </div>

            <div style="clear:both;" ></div>
            <div class="formLabel">

Re: xajax don't like a piece of php code (not evaluated, like skipped)

I've moved the topic to the third party plugin section.


$objResponse->append("risposta","innerHTML",fine($aFormValues));

What is the function "fine()" supposed to do? It's not defined in your example. Perhaps that causes an error. You can also try to add a ->alert('Hello World'); to find out if the responses work.

Unfortunately the plugin doesn't support any kind of debugging functions never mind the xajax debugging console, since it uses flash for the transport and everything works a bit different. I hope I can add some debugging function soon in a upcoming version.

Re: xajax don't like a piece of php code (not evaluated, like skipped)

Hi q_no, thanks for the answer.
In our example the function "fine" (regardless of what should do) is a experiment to catch an error, but if you substitute "fine($aFormValues)" with "$html" (that should be the content to put in the div "risposta", created by the foreach cicle) the problem is identical: the div "risposta" isn't populated sad
By smile

Re: xajax don't like a piece of php code (not evaluated, like skipped)

Hi, I experience the same issue.

After downloading xajax.ext.SWFupload_0.2.1.zip, extracting swfupload directory to my working copy, changing xajax and swfupload URLs to work with my setup and adding a single line to save files I am able to save files, but I do not receive response after successfully saving a file. Firebug shows no POST action. With an empty queue the text "empty queue" is displayed in "results" just like in the demo.

    function uploader($aFormValues) {
        $objResponse = new xajaxResponse();
        $html="";
        foreach ($_FILES as $key => $file) {
            $html .="
                <div style=\"border:1px solid #f0f0f0;background:#fff;padding:4px;margin-bottom:4px;\">
                    <div style=\"float:left;width:100px;\">Filename:</div>
                    <div style=\"float:left;\">".$_FILES[$key]['name']."</div>
                    <br style=\"clear:both;\" />
                    <div style=\"float:left;width:100px;\">Size:</div>
                    <div style=\"float:left;\">".$_FILES[$key]['size']."</div>
                    <br style=\"clear:both;\" />
                </div>
                "    ;
                move_uploaded_file($_FILES[$key]["tmp_name"], './upload/'.$_FILES[$key]['name']);
        }
        if ("" == $html) $html="empty queue";
        $objResponse->append("results","innerHTML",$html);
    
        return $objResponse;
    }

Environment: xajax 0.5 Beta 4, FF 2.0.0.14 / IE6, PHP 5.2.5/Apache 2.2 on WindowsXP SP2

Cheers!

Re: xajax don't like a piece of php code (not evaluated, like skipped)

Follow up, after deleting my xajax lib (version 0.5 (beta 4)) and copying whole lib from ajax.ext.SWFupload_0.2.1.zip the "results" section is displayed correctly following an upload. What is the difference between original lib and the one provided in this archive, which is supposedly 0.5b4 as well...?

Re: xajax don't like a piece of php code (not evaluated, like skipped)

vonholl, the packaged xajax from the swfupload is a SVN release. It contains alot of internal code optimizisations that are necessary for SWFupload plugin. Since I'm lazy as nearly every programmer I didn't wanted to maintain different versions of the SWFupload plugin (for beta4 + SVN revs). I wish we had enough time to get the stable 0.5 finally out, but our bosses keep as *very* busy and so anyone who wants to enjoy the new features has to stick with the SVN revisions. :-|
Consider the SWFupload as preview release - not as full stable version, though it works pretty good and I don't know any major bugs.

Re: xajax don't like a piece of php code (not evaluated, like skipped)

Hi q_no, thanks for explanation. Yes, this is the pain with working on latest features - one is never really up to date smile Is it reasonable to assume that this SVN release is more stable than 0.5b4?

Re: xajax don't like a piece of php code (not evaluated, like skipped)

Well, I can't swear that it's more stable than the beta4b release, but it works pretty good. We've had some issues latetly with the getFormValues function and multi-select fields but it's fixed now. I have a new SWFupload vers almost ready, which again builds upon a never SVN rev. I'm using that rev in all my current projects and couldn't find any major bugs. I guess that rev is going to be the next RC1 release as soon as we get the docs and some other missing features done.