I tried but I got some error like Pagefile::deleteAll does not exist or is not callable in this context
Or how can I enforce File field to have recent one when I try to re-upload the file to that field.
My file field name is document and I try to edit page using id from different page.
My code Is...................
$message = '';
if($input->post->edit){
$upload_path = $config->paths->assets.'uploads'.$pages->get($input->get->id)->parent->path;
$wu = new WireUpload('upload');
$wu->setMaxFiles(1);
$wu->setOverwrite(true);
$wu->setDestinationPath($upload_path);
$wu->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf', 'doc', 'docx', 'xls', 'xlsx'));
$documents = $wu->execute();
if(!$wu->getErrors()){
$ep = $pages->get($input->get->id);
$ep->of(false);
$ep->document->deleteAll();
foreach($documents as $document) {
$ep->document = $upload_path . $document;
}
$ep->setOutputFormatting(false);
$ep->save();
$ep->setOutputFormatting(true);
$message .= "<p class='message success'>Files uploaded!</p>";
} else {
foreach($documents as $document) unlink($upload_path . $document);
foreach($wu->getErrors() as $error) $message .= "<p class='error'>$error</p>";
}
}