Jump to content
Sign in to follow this  
Marvin

[SOLVED] Showing an uploaded file at the table and open it at new tab

Recommended Posts

Hello,

I'm new at process wire and i want to make an web using upload file and showing it at the table as a link to open it at the new tab. I wa succed while upload a file, but how i showing it as a link at the table to open it at the new tab of my browser? Any suggestion may helpfull

Here i attach my code below :

This code is for upload it to back-end (process wire)


<?php
  $note = $note2 = $hidden ="";
  if($input->post->submit){
    $upload_path = $config->paths->assets.'files/upload/';
    if(!is_dir($upload_path)){
      if(!wireMkdir($upload_path)) throw new WireException("No upload path");
    }
    $original = $sanitizer->text($input->post->original);
    $indonesia = $sanitizer->text($input->post->indonesia);
    $other = $sanitizer->text($input->post->other);
    $composer = $sanitizer->text($input->post->composer);

    if(!$original || !$indonesia || !$other || !$composer){
      $note = "Data tidak lengkap";
    } else {
      $newFile = new WireUpload("song_files");
      $newFile->setMaxFiles(1);
      $newFile->setOverwrite(false);
      $newFile->setDestinationPath($upload_path);
      $newFile->setValidExtensions(array('pdf','docx','doc'));
      $files = $newFile->execute();

      if(!count($files)) {
        $newFile->error("No files received, so not creating page.");
        return false; 
      }

      $newImg = new WireUpload("img_files");
      $newImg->setMaxFiles(1);
      $newImg->setOverwrite(false);
      $newImg->setDestinationPath($upload_path);
      $newImg->setValidExtensions(array('jpeg','jpg','png','gif'));
      $files = $newImg->execute();

      if(!count($files)) {
        $newImg->error("No files received, so not creating page.");
        return false; 
      }

      $newPage = new Page();
      $newPage->template = "files";
      $newPage->parent = $pages->get("/files/");
      $newPage->title = $original;
      $newPage->text_1 = $indonesia;
      $newPage->text_2 = $other;
      $newPage->text_3 = $composer;
      $newPage->of(false);
      $newPage->save();

      foreach($files as $filename) {
        $filepath = $upload_path . $filename;
        $newPage->files->add($filepath);
        $newPage->message("Add file : $filename");
        unlink($filepath);
      }
      $newPage->save();
    }
  }
?>

and this code to showing it as a link at the table

<table class="border">
          <tr>
            <th>No.</th>
            <th>Original Song Title</th>
            <th>Indonesia Song Title</th>
            <th>Other Song Title</th>
            <th>Composer</th>
            <th>File (pdf)</th>
          </tr>
          <?php
            $num = 1;
            $song;
            foreach($pages->get("/files/")->children as $child) { //showing every child at files parent directory
              $page == $child;
              $song = $pages->get("/files/".$child->id."/")->files; //showing uploaded files at child directory
              echo $child->id;
              echo "<tr><td>".$num++.".</td><td>".$child->title."</td><td>".$child->text_1."</td><td>".$child->text_2."</td><td>".$child->text_3."</td><td><a href='".$song->httpUrl."'</a>".$song->name."</td></tr>";
            }
          ?>
        </table>

Thank you for any suggestion

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Marvin
      Hello, excuse me
      I'm new at processwire, i want to ask about a master detail system (Inheritance system) using a processwire. Can we create a Inheritance table using a processwire, and how we create it? Thank you for the help
    • By picarica
      so hello there i have fiel field type i have lots of stuff there, and also an image i can easily get image from that field using
                                                        
      $options = array('quality' => 85, 'upscaling' => true, 'cropping' => 'north', 'sharpening' => 'medium'); $word = ".png"; // Test if string contains the word foreach($childgames->subor_hry as $file) { if(strpos($file, $word) !== false){ /* $imger = $file->size(473, 266, $options); */ echo $file; /* echo $file->url; */ } } so i get the fiel i tried invoking size on it like the commented out part and it doesnt work i get error Oh snizzle… Error:     Exception: Method Pagefile::size does not exist or is not callable in this context (in
      what am i doing wrong? can you guys help me by all logic this should work
    • By Max Esnée
      Hi,
      When I upload a large(ish) SVG (≈120ko in this case) into an image field, it tends to get stuck at 100% and block the whole website. If I force refresh the admin page, the svg has not been uploaded. The file is correctly copied into the assets folder though. Other svg tends to be uploaded fine albeit I've noticed that pages containing svg images in the admin are very slow to load generally. Other pages using the same template but with jpeg or png images are much faster to load.
      I get the following error in the JS console:

      I develop locally using MAMP on macOS and I'm using Firefox. I'm using the last ProcessWire version (3.0.165).
      I also tested in Chrome and got the same error.
    • By Marvin
      Hi,
      I'm still new at processwire, i want to ask, i was create a website with sign in system, but i want to add a access roles/permission for each user at my website. For now, i just can create a login user without any permission and the user data became as a pages in my processwire.
      Here i attach my code for login
      <?php $note = $note2 = $hidden =""; if($input->get->id == "logout") { $session->remove('login_id'); } if($input->post->submit) { $email = $sanitizer->email($input->post->email); $pass = $sanitizer->text($input->post->pass); $result = $pages->find("email=$email, text_1=$pass"); if(!$email || !$pass) { $note = "Data belum lengkap"; } else { if($result->count > 0) { $session->login_id = "$result"; $hidden = "style = 'diplay:none'"; $url=$pages->get("/files/")->httpUrl; header("Location:$url"); die(); } else { $note = "Akun tidak ditemukan"; } } } ?> And this code for login form
      <div class="frow-container"> <div class="frow centered mt-50"> <div class="col-md-1-3"> <div class="box p-40 shadow-light"> <h2 class="mb-20 text-center" <?=$hidden?>>Database Partitur<br>GII HIT</h2> <form method="post" <?=$hidden?>> <label>Username <input type="text" name="email"></label> <label>Password <input type="password" name="pass"></label> <input type="submit" name="submit" value="Masuk"> </form> <p class="notif"><?=$note;?></p> <div class="text-center"><?=$note2;?></div> </div> </div> </div> </div> Just for remember, my user data now is a pages, and i cannot give any permission to user data.
      Thank you very much for help.
    • By theoretic
      Hi there! And thanks for Processwire!
      It appears there's a possible bug in Processwire 3.0.170 concerning file and/or image inputfield. Creating such a field results in the following error:

      Fatal Error: Uncaught Error: Call to a member function get() on null
      The inputfield is created however. The closer look reveals a problem at line 60 in wire\modules\Fieldtype\FieldtypeFile\config.php:
      if(!$value) $value = $fieldtype->get('defaultFileExtensions'); Commenting this line removes the problem, but the newly created inputfield requires 'Allowed file extensions' config option to be set (which is rather expectable since i commented the above-cited line of code). Never faced this problem before, hope it can be resolved.
×
×
  • Create New...