Jump to content

Recommended Posts

Posted

So I am using ajax to upload an image, but I am getting the error "Method WireUpload:: save does not exist or is not callable". I am not quite sure how to go about fixing this (at the moment).

elseif($config->ajax && $input->urlSegment1 == "upload-preview") {
    $u = $config->paths->assets . "files/pdfs/";

    $title = $sanitizer->text($_POST['title']);

    $p = new Page();
    $p->template = "preview";
    $p->parent = $pages->get("/previews/");
    $p->name = $title;
    $p->title = $title;
    $p->save();
    $p->setOutputFormatting(false);

    $u = new WireUpload('preview_image');
    $u->setMaxFiles(1);
    $u->setOverwrite(false);
    $u->setDestinationPath($p->preview_image->path());

    $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf'));
    foreach($u->execute() as $filename) { $p->preview_image->add($filename); }

    $u->save();
}

I compared my code to something I did previously (though previously I just posted to the current template file, not through ajax) which works, but this doesnt seem to be working. I have the _init.php file prepending as well. Does anyone have any ideas of what might be happening?

Posted

You should save the page after finishing with your upload.

$p->save();

instead of 

$u->save();

WireUpload doesn't have any save method (that's what the error message tells you)

  • Like 1
Posted

Also i would give the new page only a title with your text sanitizer and let ProcessWire handle the name of the page (in case the pagename already exists).
If you would like to set also the page name then use the $sanitizer->pageName().

  • Like 1

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
×
×
  • Create New...