Support

Account

Home Forums Add-ons Repeater Field Full local file system path?

Unread

Full local file system path?

  • I am trying to create a zip with every archive added to a repeater field.
    With the code below it appears something is wrong with the first parameter (filename) of the addFile, it wants a full local file system path to the files and I am failing to provide it.

    Any insights?

    
    function gerar_zip_dos_materiais( $post_id ) {
      $arquivos = get_field('materiais');
      $error = '';
      if ($arquivos) {
        if(extension_loaded('zip')){
    
          $zip = new ZipArchive(); // Carrega a biblioteca zip
          $nome_curto = $slug = basename(get_permalink());
          date_default_timezone_set('America/Bahia');
          $data_agora = date('Ymd_His');
          $nome_do_zip = $nome_curto . '-' . $data_agora . '.zip';
    
          if($zip->open($nome_do_zip, ZIPARCHIVE::CREATE)!==TRUE){
            $error .=  "Falhou ao criar o zip desta vez!";
          }
    
          foreach($arquivos as $arquivo) {
            $o_arquivo = $arquivo['arquivo_do_material'];
            $o_nome_do_arquivo = $arquivo['nome_do_material'];
            $zip->addFile( $o_arquivo, $o_nome_do_arquivo );
          }
    
          if ($zip->close() === false) {
            exit("Falou ao fechar o zip desta vez!");
          }
    
          wp_upload_bits( $nome_do_zip, null, $zip );
        }
      }
    }
    
Viewing 1 post (of 1 total)

The topic ‘Full local file system path?’ is closed to new replies.