We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 17499 ☆ A M B ☆
    • 872 Posts
    I have tried to convert one of my application to Revolution and having problem doing it like i would like to.

    The first issue is not a real blocker.

    I’m trying to use a flash uploader (jquery uploadify) with a connector like in the tutorial.
    With this script, you can precise extra paramaters with the option scriptdata:

    $("#myid").uploadify({
    	'uploader'       : '/assets/components/upload/flash/uploadify.swf',
    	'script'         : '/assets/components/upload/connector.php',
    	'scriptData'	 : {'action':'upload', 'ctx':'web'}
    });
    


    Unfortunately, the upload break in the connector with this line

    <?php
    require_once MODX_CONNECTORS_PATH.'index.php';
    


    It’s not really a blocker because the same code work if i use a file upload.php with just the upload code needed.
    But i can’t use MODx function with the script (it works fine with Evolution).

    The second problem is a blocker.
    The file uploaded is an Excel file uploaded in "assets/files/" directory.

    When i try to access it with php and the function file_exist, it throw me a fatal error telling me that the file does not exist or is not readable.

    <?php
    
    //The line that attempting to load the file
    $objPHPExcel = $objReader->load('assets/files/myfile.xls');
    
    //The function used to load the file in the Excel class
    if (!file_exists($pFilename)) {
    			throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
    }
    


    The same code works well with Evo too.

    Any ideas what could be the problem?
      • 28215
      • 4,149 Posts
      Quote from: lossendae at Nov 02, 2009, 03:45 AM

      <?php
      require_once MODX_CONNECTORS_PATH.'index.php';
      


      It’s not really a blocker because the same code work if i use a file upload.php with just the upload code needed.
      But i can’t use MODx function with the script (it works fine with Evolution).
      First off, I would recommend putting a include statement including the upload.php in a Snippet, and then put that snippet call into a Resource with a (blank) Template. Give the resource an alias like, ’connector’, and point your AJAX calls to the resource. That way, you don’t have to do the MODX_CONNECTORS_PATH includes, but you still get the $modx object.


      $objPHPExcel = $objReader->load(’assets/files/myfile.xls’);
      Looks like you’re specifying a relative path, rather than an absolute one. Try:
      $objPHPExcel = $objReader->load($modx->getOption('base_path').'assets/files/myfile.xls');
      
        shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
        • 17499 ☆ A M B ☆
        • 872 Posts
        Thanks for your answers shaun,

        Both solutions worked well but i’ve another error with the following modx function:

        <?php
        return $modx->error->success($response);
        

        Which return
        Call to a member function success() on a non-object
        


        Any idea?
          • 17499 ☆ A M B ☆
          • 872 Posts
          Here is the complete code for which error->success is not working.

          <?php
          include ($this->config['processors_path'].'PHPExcel/IOFactory.php');
          
          $objReader = PHPExcel_IOFactory::createReader('Excel2007');
          $objReader->setReadDataOnly(true);
          $objPHPExcel = $objReader->load($modx->getOption('base_path')."assets/files/brands.xlsx");
          
          $objWorksheet = $objPHPExcel->getActiveSheet();
          
          $highestRow = $objWorksheet->getHighestRow(); 
          $highestColumn = $objWorksheet->getHighestColumn(); 
          
          for ($row = 2; $row <= $highestRow; ++$row) {
          	$field = $modx->newObject('Brands');
          	$field->set('name', $objWorksheet->getCellByColumnAndRow(1, $row)->getValue());
          	if($field->save() == false){
          		return $modx->error->failure($modx->lexicon('upload.error_brand_save'));
          	}
          }
          return $modx->error->success();
          


          I can’t figure out where the problem is, i did use similar code for other snippets, plus i can access the modx object since datas are correctly put in the database.

          Am i missing something?

          Edit: I’ll use a basic json_encode since it works and not use the modx function for now, and come back to this issue when i find more time to do so.