/** * Copy folder to new location */ public function copy($newpath = "") { $path = $this->getPath(); $newpath = Sanitize::toPath($newpath); $output = 0; if (is_dir($path) && !empty($newpath)) { mkdir($newpath, 0777, true); $stream = opendir($path); while (false !== ($item = @readdir($stream))) { if ($item === "." || $item === "..") { continue; } $from = Sanitize::toPath($path . "/" . $item); $to = Sanitize::toPath($newpath . "/" . $item); if (is_dir($from)) { $folder = new Folder($from); $folder->copy($to) && $output++; continue; } if (is_file($from)) { $file = new File($from); $file->copy($to) && $output++; continue; } } @closedir($stream); } return $output ? true : false; }
/** * Send file download response */ public function download($path = '') { $this->flushHeaders(); $this->flushContents(); if (!empty($path)) { if (Validate::isUrl($path)) { $this->redirect($path); } if (is_file($path) !== true) { $this->setText(404, '404: The requested file could not be found.'); $this->send(); } $file = new File($path); $this->cacheExpire('-1 week'); $this->setStatusCode(200); $this->setContentType($file->getMimeType()); $this->setHeader('Content-Description', 'File Transfer', true); $this->setHeader('Content-Disposition', 'attachment; filename=' . $file->getSafeName() . ';', true); $this->setHeader('Content-Length', $file->getSize(), true); $this->setHeader('Content-Transfer-Encoding', 'binary', true); $this->sendHeaders(); @readfile($file->getPath()); exit; } throw new Exception('Tried to download a file without providing a valid file path.'); }