Topic: Post -> File and use it in function.

Hello.
I need to upload a file and use it in a function, I'm having some troubles, though.

Here is my code.

                        <form action="index.php" id="filecsv"  method="post" enctype="multipart/form-data">
                          <input type="file" multiple="multiple" id="file" name="up_csv[]"/><br />
                          <?php
                              //tipos de archivos permitidos
                    $extensioncsv = array('csv', 'txt');
                    //destino
                    //multicargador de archivos
                    $vt=0;
                    for($i=0;$i<count($_FILES['up_csv']['size']);$i++){
                        for ($j=-1; $j<count($extensioncsv); $j++) {
                            if (strripos($_FILES['up_csv']['name'][$i], $extensioncsv[$j])!== false) {
                            $destino = $ruta.$_FILES['up_csv']['name'][$i];
                            move_uploaded_file($_FILES['up_csv']['tmp_name'][$i],'./csv/'.$_FILES['up_csv']['name'][$i]);
                            $up_tamanio +=$_FILES['up_csv']['size'][$i];
                            $vt=$vt+1;    
                            break; 
                            }  
                            }
                            }
                          ?>
                           <input type="button" value="Crear" onClick="xajax_makecsv(xajax.getElementById('file'));" />
                      </form>

this my function

require_once("xajax.inc.php"); 

$xajax = new xajax(); 
$xajax->registerFunction("makecsv"); 

function makecsv($csv) {

$doc = new DOMDocument();

   $row = 1;
   $handle = fopen($csv, "r");
     # Rows Counter
    $csvxrow = file($csv);
    $csvxrow[0] = chop($csvxrow[0]);
    $anzdata = count($csvxrow);
   while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
       $num = count($data);
       $row++;
              #Load Predefined XML Template      
             $xml2 = $xml;
             $xmlruta = './Templates/';
             $xml = $xmlruta.$data[1].'.xml';
             $doc->load($xml);  
             $xp = new DOMXPath($doc);
         for ($c=0; $c < $num; $c++) {
                       .............
         }
               $name = $data[0] .'-'. $data[1];
               $doc->formatOutput = true;
          echo $doc->saveXML();
               $rutafinal = './XML/';
               $doc->save($rutafinal.$name.'.xml');
       
    }
fclose($handle);

    echo $anzdata . " XML Creados" . "<br />";  

return $objResponse->save();
return $data;
}

$xajax->processRequests(); 

Any idead ?

Re: Post -> File and use it in function.

File posting doesn't work via the xajax function. We always post the file to a hidden iframe with a target of a PHP file and process that way.  you can then trigger a call to the xajax function if extra processing is required.

Re: Post -> File and use it in function.

My function doesn't return nothing.... I just need to make the function.

Re: Post -> File and use it in function.

If you are trying to return the CSV file to the browser, there is no need for xajax. Just direct link to a program that generates it.