Jump to content

add() on a non-object error


Manaus
 Share

Recommended Posts

Hello,

I have some troubles on adding an uploaded file to a page, here is the code:

<? 

$theReply = new Page();
$theReply->parent = $theparentPage;
$theReply->template = $templates->get("mytemplate");
$theReply->of(false);
$theReply->name = $sanitizer->name(first_n_words($input->post->reply, 5));
$theReply->save();
$theReply->of(true);

if ($_FILES['attachment']['size'] > 0) {
   $upload_path = $config->paths->assets . "files/attachments/"; 
   
   $doc_Upload = new WireUpload('attachment'); 
   $doc_Upload->setMaxFiles(1);  
   $doc_Upload->setOverwrite(false);  
   $doc_Upload->setDestinationPath($upload_path); 
   $doc_Upload->setValidExtensions($allowedExtensions); 
   $doc_Uploaded = $doc_Upload->execute(); 

   foreach ($doc_Uploaded as $du) {
      $pathname = $upload_path . $du;
      $theReply->documents->add($pathname); // <===== Call to a member function add() on a non-object
      unlink($pathname);
   }
   $theReply->save();
   
   [...]
}

$theReply exists, $doc_Uploaded exists, still I get the error in the comment

Any help would be greatly appreciated

Thanks

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...