Jump to content

WireUpload not saving files


h4r4ld
 Share

Recommended Posts

Hi,

I'm going mad, but I bet its just a simple thing...

I try to upload a file with wireupload, there is no error reported from WireUpload->getErrors and the page to store its data is beeing generated. Everything seems fine, the path to the newly uploaded file is stored and every value is fetched like suppost, there is just no file in the specified directory on my ftp. I even tried to chmod 0777 the upload directory, no change.

<?php
if($input->post->barcode){
  
  $message = '';
  $upload_path = $config->paths->root . "file_uploads/doctree/";
 
  // new wire upload
  $u = new WireUpload('uploads');
  $u->setMaxFiles(1);
  $u->setMaxFileSize(200*1024);
  $u->setOverwrite(false);
  $u->setDestinationPath($upload_path);
  $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'txt', 'pdf', 'tif'));
  
  // execute upload and check for errors
  $files = $u->execute();
  if(!$u->getErrors()){
  
      // create the new page to add the file
      $p = new Page();
      $p->setOutputFormatting(false);
      $p->template = 'documentHolder';                
      $p->parent = wire('pages')->get('/doctree/');  
      $p->status = "hidden";                          
      $barcode = mb_strtoupper($input->post->barcode, 'UTF-8');
      $p->name = $barcode;                           
      $p->title = $barcode;
      $p->docdescription = $input->post->description;
      $p->doccaption = $input->post->title;
      $p->docownerid = $user->id;
      $p->docvalue = $input->post->value;
      $p->docvendor = $input->post->vendor;
      $p->doccategorie = $input->post->categorie;
      foreach($files as $filename) {
          $p->docfile = $upload_path . $filename;
      }
      // save page
      $p->save();
      
      // remove all tmp files uploaded
      foreach($files as $filename) unlink($upload_path . $filename);
      $message .= "<p class='message'>Files uploaded!</p>";
  } else {
  
      // remove files
      foreach($files as $filename) unlink($upload_path . $filename);
      
      // get the errors
      foreach($u->getErrors() as $error) $message .= "<p class='error'>$error</p>";
  }
} else {
?>
  
    <form action="./" class="form-horizontal row-border" method="post" data-validate="parsley" 
id="validate-form" enctype="multipart/form-data">

      <div class="form-group">
        <label class="col-sm-3 control-label">File input</label>
        <div class="col-sm-4">
            <div class="fileinput fileinput-new" data-provides="fileinput">
                <div class="input-group">
                    <div class="form-control uneditable-input" data-trigger="fileinput">
                        <i class="fa fa-file fileinput-exists"></i> <span class="fileinput-filename"></span>
                    </div>
                    <span class="input-group-addon btn btn-default btn-file">
                        <span class="fileinput-new">Select file</span>
                        <span class="fileinput-exists">Change</span>

                        <input type="file" name="uploads[]" id="uploads[]" size="40" accept="image/jpg,image/jpeg,image/gif,image/png,image/tiff,application/pdf,text/plain"/>

                    </span>
                    <a href="#" class="input-group-addon btn btn-default fileinput-exists" data-dismiss="fileinput">Remove</a>
                </div>
                Allowed filetypes : *.jpg, *.jpeg, *.gif, *.png, *.txt, *.pdf, *.tif
            </div>
          </div>
      </div>
    
      <!-- some more inputs... -->
      
      <button class="btn-midnightblue btn" type="submit" onclick="javascript:$( '#validate-form').parsley( 'validate' );">Submit</button>
    </form>
  <?php } ?>

Based on this: https://gist.github.com/somatonic/4150974

Link to comment
Share on other sites

You need to save the page first, then add the files, then save again (see example here)...So, are you sure the files are not getting uploaded or you are removing them (the code after ....// remove all tmp files uploaded) after saving the page?

Edited by kongondo
  • Like 2
Link to comment
Share on other sites

You need to save the page first, then add the files, then save again (see example here)...So, are you sure the files are not getting uploaded or you are removing them (the code after ....// remove all tmp files uploaded) after saving the page?

Unlink should not effect files uploaded, but files that are linked to upload, so that shouldn't be any of a problem.

*Edit:

Uhuh,

you got me there, seems like I totally messed up the upload script from soma. Thanks for open my eyes.

Do i need to save them twice always?

As far as I understood from the docs its only needed if the field is an imagefield?

I just store the link to the uploaded files in a field, so its nothing more than text.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...