本文整理汇总了PHP中Filesystem::delete方法的典型用法代码示例。如果您正苦于以下问题:PHP Filesystem::delete方法的具体用法?PHP Filesystem::delete怎么用?PHP Filesystem::delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Filesystem
的用法示例。
在下文中一共展示了Filesystem::delete方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: tearDown
public function tearDown()
{
try {
$this->filesystem->delete('file.txt');
} catch (FileNotFoundException $e) {
}
$this->filesystem->deleteDir('files');
}
示例2: clear
/**
* Clear all Cache
*
* @museDescription Clears all cached items in document root cache directory
*
* @return void
*/
public function clear()
{
// Path to cache folder
$cacheDir = PATH_APP . DS . 'cache' . DS . '*';
// Remove recursively
foreach (glob($cacheDir) as $cacheFileOrDir) {
$readable = str_replace(PATH_APP . DS, '', $cacheFileOrDir);
if (is_dir($cacheFileOrDir)) {
if (!Filesystem::deleteDirectory($cacheFileOrDir)) {
$this->output->addLine('Unable to delete cache directory: ' . $readable, 'error');
} else {
$this->output->addLine($readable . ' deleted', 'success');
}
} else {
// Don't delete index.html
if ($cacheFileOrDir != PATH_APP . DS . 'cache' . DS . 'index.html') {
if (!Filesystem::delete($cacheFileOrDir)) {
$this->output->addLine('Unable to delete cache file: ' . $readable, 'error');
} else {
$this->output->addLine($readable . ' deleted', 'success');
}
}
}
}
$this->output->addLine('Clear cache complete', 'success');
}
示例3: testDispatchShouldRenderOutputWhenViewExists
/**
* @testdox dispatch should render output when only view exists
*/
public function testDispatchShouldRenderOutputWhenViewExists()
{
// create a test view
Filesystem::createDir('app/views/missing', 0777);
Filesystem::write('app/views/missing/test.htm.php', 'working');
$output = Dispatcher::dispatch(array('controller' => 'missing', 'action' => 'test') + self::$defaults);
// destroy the test view
Filesystem::delete('app/views/missing');
$this->assertNotEquals('', $output);
}
示例4: clear
/**
* Clear Site.css & Site.less.cache files
*
* @return void
*/
public function clear()
{
$cacheDir = PATH_APP . DS . 'cache';
$files = array('site.css', 'site.less.cache');
// Remove each file
foreach ($files as $file) {
if (!is_file($cacheDir . DS . $file)) {
$this->output->addLine($file . ' does not exist', 'warning');
continue;
}
if (!Filesystem::delete($cacheDir . DS . $file)) {
$this->output->addLine('Unable to delete cache file: ' . $file, 'error');
} else {
$this->output->addLine($file . ' deleted', 'success');
}
}
// success!
$this->output->addLine('All CSS cache files removed!', 'success');
}
示例5: actionDelete
public function actionDelete($id = 0)
{
$request = $this->request;
if (!$request->isPost()) {
return;
}
$del = $request->post['del'];
if ($del == 'Yes' && $id > 0) {
try {
$this->items->delete($id);
$this->flashMessage('Item has been deleted.', 'ok');
$this->redirect('default');
} catch (DibiException $e) {
$this->flashMessage('Delete error!' . $e, 'err');
}
} else {
$this->flashMessage('There is some problem with deleting this item!', 'err');
$this->redirect('default');
}
}
示例6: cleanTempUploads
/**
* Close tickets in a pending state for a specific amount of time
*
* @param object $job \Components\Cron\Models\Job
* @return boolean
*/
public function cleanTempUploads(\Components\Cron\Models\Job $job)
{
$params = $job->get('params');
$sconfig = Component::params('com_support');
$path = PATH_APP . DS . trim($sconfig->get('webpath', '/site/tickets'), DS);
$days = intval($params->get('support_tickettemp_age', '7'));
$old = time() - $days * 24 * 60 * 60;
$dirIterator = new DirectoryIterator($path);
foreach ($dirIterator as $file) {
if (!$file->isDir()) {
continue;
}
$name = $file->getFilename();
if (substr($name, 0, 1) != '-') {
continue;
}
if (abs($name) < $old) {
Filesystem::delete($file->getPathname());
}
}
}
示例7: admin
public function admin($action = NULL)
{
if ($files = glob($this->dir . DS . 'js/jquery*')) {
$current_script = reset($files);
preg_match('#jquery-([\\d.]+)(\\.min)?\\.js#', $current_script, $matches);
$current_version = $matches[1];
$code = file_get_contents('http://code.jquery.com/');
preg_match('#/jquery-([\\d\\.]+)\\.min\\.js#imsU', $code, $matches);
$server_script = 'http://code.jquery.com' . $matches[0];
$server_version = $matches[1];
if (version_compare($server_version, $current_version, '>')) {
if ($action = 'update') {
Filesystem::delete($current_script);
copy($server_script, dirname($current_script) . DS . basename($server_script));
success(t('jQuery library has been update successfully!'));
} else {
info(t("Notice, jQuery framework has been updated to version <b>%s</b>. Current version is <b>%s</b>.", 'jQuery', $server_version, $current_version) . '<a href="' . Url::link('admin/jquery/update/') . '" class="button">' . t('Update') . '</a>');
}
}
}
}
示例8: cleanGroupFolders
/**
* Remove unused group folders
*
* @param object $job \Components\Cron\Models\Job
* @return boolean
*/
public function cleanGroupFolders(\Components\Cron\Models\Job $job)
{
// get group params
$groupParameters = Component::params('com_groups');
// get group upload path
$groupUploadPath = ltrim($groupParameters->get('uploadpath', '/site/groups'), DS);
// get group folders
$groupFolders = Filesystem::directories(PATH_APP . DS . $groupUploadPath);
// loop through each group folder
foreach ($groupFolders as $groupFolder) {
// load group object for each folder
$hubzeroGroup = \Hubzero\User\Group::getInstance(trim($groupFolder));
// if we dont have a group object delete folder
if (!is_object($hubzeroGroup)) {
// delete folder
Filesystem::delete(PATH_APP . DS . $groupUploadPath . DS . $groupFolder);
}
}
// job is no longer active
return true;
}
示例9: batchTask
/**
* Batch resume download
*
* @return void
*/
public function batchTask()
{
// Login required
if (User::isGuest()) {
\Notify::warning(Lang::txt('COM_JOBS_PLEASE_LOGIN_ACCESS_EMPLOYER'));
$this->login();
return;
}
// Check authorization
if (!$this->_admin && !$this->_emp) {
App::redirect(Route::url('index.php?option=com_jobs&task=subscribe'));
}
// Incoming
$pile = Request::getVar('pile', 'all');
// Zip the requested resumes
$archive = $this->_archiveResumes($pile);
if ($archive) {
// Initiate a new content server and serve up the file
$xserver = new \Hubzero\Content\Server();
$xserver->filename($archive['path']);
$xserver->disposition('attachment');
$xserver->acceptranges(false);
$xserver->saveas(Lang::txt('JOBS_RESUME_BATCH=Resume Batch'));
$result = $xserver->serve_attachment($archive['path'], $archive['name'], false);
// Delete downloaded zip
\Filesystem::delete($archive['path']);
if (!$result) {
throw new Exception(Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 500);
} else {
exit;
}
} else {
App::redirect(Route::url('index.php?option=com_jobs&task=dashboard'), Lang::txt('COM_JOBS_ERROR_ARCHIVE_FAILED'), 'error');
}
}
示例10: downloadresponses
/**
* Generate detailed responses CSV files and zip and offer up as download
*
* @return void
**/
private function downloadresponses()
{
require_once PATH_CORE . DS . 'components' . DS . 'com_courses' . DS . 'models' . DS . 'formReport.php';
// Only allow for instructors
if (!$this->course->offering()->section()->access('manage')) {
App::abort(403, 'Sorry, you don\'t have permission to do this');
}
if (!($asset_ids = Request::getVar('assets', false))) {
App::abort(422, 'Sorry, we don\'t know what results you\'re trying to retrieve');
}
$protected = 'site' . DS . 'protected';
$tmp = $protected . DS . 'tmp';
// We're going to temporarily house this in PATH_APP/site/protected/tmp
if (!Filesystem::exists($protected)) {
App::abort(500, 'Missing temporary directory');
}
// Make sure tmp folder exists
if (!Filesystem::exists($tmp)) {
Filesystem::makeDirectory($tmp);
} else {
// Folder was already there - do a sanity check and make sure no old responses zips are lying around
$files = Filesystem::files($tmp);
if ($files && count($files) > 0) {
foreach ($files as $file) {
if (strstr($file, 'responses.zip') !== false) {
Filesystem::delete($tmp . DS . $file);
}
}
}
}
// Get the individual asset ids
$asset_ids = explode('-', $asset_ids);
// Set up our zip archive
$zip = new ZipArchive();
$path = PATH_APP . DS . $tmp . DS . time() . '.responses.zip';
$zip->open($path, ZipArchive::CREATE);
// Loop through the assets
foreach ($asset_ids as $asset_id) {
// Is it a number?
if (!is_numeric($asset_id)) {
continue;
}
// Get the rest of the asset row
$asset = new \Components\Courses\Tables\Asset($this->db);
$asset->load($asset_id);
// Make sure asset is a part of this course
if ($asset->get('course_id') != $this->course->get('id')) {
continue;
}
if ($details = \Components\Courses\Models\FormReport::getLetterResponsesForAssetId($this->db, $asset_id, true, $this->course->offering()->section()->get('id'))) {
$output = implode(',', $details['headers']) . "\n";
if (isset($details['responses']) && count($details['responses']) > 0) {
foreach ($details['responses'] as $response) {
$output .= implode(',', $response) . "\n";
}
}
$zip->addFromString($asset_id . '.responses.csv', $output);
} else {
continue;
}
}
// Close the zip archive handler
$zip->close();
if (is_file($path)) {
// Set up the server
$xserver = new \Hubzero\Content\Server();
$xserver->filename($path);
$xserver->saveas('responses.zip');
$xserver->disposition('attachment');
$xserver->acceptranges(false);
// Serve the file
$xserver->serve();
// Now delete the file
Filesystem::delete($path);
}
// All done!
exit;
}
示例11: uploadTask
/**
* Upload a file
*
* @return void
*/
public function uploadTask()
{
// Check if they're logged in
/*if (User::isGuest())
{
$this->displayTask();
return;
}*/
if (Request::getVar('no_html', 0)) {
return $this->ajaxUploadTask();
}
// Ensure we have an ID to work with
$ticket = Request::getInt('ticket', 0, 'post');
$comment = Request::getInt('comment', 0, 'post');
if (!$ticket) {
$this->setError(Lang::txt('COM_SUPPORT_NO_ID'));
$this->displayTask();
return;
}
// Incoming file
$file = Request::getVar('upload', '', 'files', 'array');
if (!$file['name']) {
$this->setError(Lang::txt('COM_SUPPORT_NO_FILE'));
$this->displayTask();
return;
}
// Build the upload path if it doesn't exist
$path = PATH_APP . DS . trim($this->config->get('filepath', '/site/tickets'), DS) . DS . $ticket;
if (!is_dir($path)) {
if (!Filesystem::makeDirectory($path)) {
$this->setError(Lang::txt('Error uploading. Unable to create path.'));
$this->displayTask();
return;
}
}
// Make the filename safe
$file['name'] = urldecode($file['name']);
$file['name'] = Filesystem::clean($file['name']);
$file['name'] = str_replace(' ', '_', $file['name']);
$ext = Filesystem::extension($file['name']);
$filename = Filesystem::name($file['name']);
while (file_exists($path . DS . $filename . '.' . $ext)) {
$filename .= rand(10, 99);
}
//make sure that file is acceptable type
if (!in_array($ext, explode(',', $this->config->get('file_ext')))) {
$this->setError(Lang::txt('COM_SUPPORT_ERROR_INCORRECT_FILE_TYPE'));
echo $this->getError();
return;
}
$filename .= '.' . $ext;
// Upload new files
if (!\Filesystem::upload($file['tmp_name'], $path . DS . $filename)) {
$this->setError(Lang::txt('ERROR_UPLOADING'));
} else {
$fle = $path . DS . $filename;
if (!\Filesystem::isSafe($file)) {
if (\Filesystem::delete($file)) {
$this->setError(Lang::txt('ATTACHMENT: File rejected because the anti-virus scan failed.'));
echo $this->getError();
return;
}
}
// Create database entry
$asset = new Attachment();
$asset->bind(array('id' => 0, 'ticket' => $ticket, 'comment_id' => $comment, 'filename' => $filename, 'description' => Request::getVar('description', '')));
if (!$asset->store(true)) {
$this->setError($asset->getError());
}
}
// Push through to the media view
$this->displayTask();
}
示例12: removeImage
/**
* Remove image
*
* @param int Image ID
* @return bool Success of Failure
*/
public function removeImage($imgId)
{
$img = $this->getImage();
if (empty($img)) {
return false;
}
if ($imgId == $img->imgId) {
$this->data->image = false;
// Remove the actual file
$config = Component::params('com_storefront');
$imgWebPath = trim($config->get('collectionsImagesFolder', '/site/storefront/collections'), DS);
$path = PATH_APP . DS . $imgWebPath . DS . $this->getId();
if (!is_file($path . DS . $img->imgName)) {
return false;
}
Filesystem::delete($path . DS . $img->imgName);
return true;
}
}
示例13: _fileDelete
/**
* Delete a file in the wiki
*
* @return void
*/
public function _fileDelete()
{
// Check if they're logged in
if (User::isGuest()) {
return $this->_files();
}
$no_html = Request::getVar('no_html', 0);
// Incoming file
$file = trim(Request::getVar('file', '', 'get'));
if (!$file) {
$this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_NO_FILE_PROVIDED'));
if ($no_html) {
ob_clean();
header('Content-type: text/plain');
echo json_encode(array('success' => false, 'error' => $this->getError()));
exit;
}
return $this->_files();
}
// Build the file path
$path = $this->_path();
// Delete the file
if (!file_exists($path . DS . $file) or !$file) {
$this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_FILE_NOT_FOUND'));
if ($no_html) {
ob_clean();
header('Content-type: text/plain');
echo json_encode(array('success' => false, 'error' => $this->getError()));
exit;
}
return $this->_files();
} else {
// Attempt to delete the file
if (!Filesystem::delete($path . DS . $file)) {
$this->setError(Lang::txt('PLG_COURSES_PAGES_ERROR_UNABLE_TO_DELETE_FILE'));
if ($no_html) {
ob_clean();
header('Content-type: text/plain');
echo json_encode(array('success' => false, 'error' => $this->getError()));
exit;
}
}
}
if ($no_html) {
return $this->_fileList();
}
// Push through to the media view
return $this->_files();
}
示例14: getPreview
/**
* Get preview image
*
* @return mixed
*/
public function getPreview($model, $hash = '', $get = 'name', $render = '', $hashed = NULL)
{
if (!$model instanceof Project) {
return false;
}
$image = NULL;
if (!$hashed) {
$hash = $hash ? $hash : $this->get('hash');
$hash = $hash ? substr($hash, 0, 10) : '';
// Determine name and size
switch ($render) {
case 'medium':
$hashed = md5($this->get('name') . '-' . $hash) . '.png';
$maxWidth = 600;
$maxHeight = 600;
break;
case 'thumb':
$hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash, 'png') : NULL;
$maxWidth = 80;
$maxHeight = 80;
break;
default:
$hashed = $hash ? Helpers\Html::createThumbName($this->get('name'), '-' . $hash . '-thumb', 'png') : NULL;
$maxWidth = 180;
$maxHeight = 180;
break;
}
}
// Target directory
$target = PATH_APP . DS . trim($model->config()->get('imagepath', '/site/projects'), DS);
$target .= DS . strtolower($model->get('alias')) . DS . 'preview';
$remoteThumb = NULL;
if ($this->get('remoteId') && $this->get('modified')) {
$remoteThumb = substr($this->get('remoteId'), 0, 20) . '_' . strtotime($this->get('modified')) . '.png';
}
if ($hashed && is_file($target . DS . $hashed)) {
// First check locally generated thumbnail
$image = $target . DS . $hashed;
} elseif ($remoteThumb && is_file($target . DS . $remoteThumb)) {
// Check remotely generated thumbnail
$image = $target . DS . $remoteThumb;
// Copy this over as local thumb
if ($hashed && Filesystem::copy($target . DS . $remoteThumb, $target . DS . $hashed)) {
Filesystem::delete($target . DS . $remoteThumb);
}
} else {
// Generate thumbnail locally
if (!file_exists($target)) {
Filesystem::makeDirectory($target, 0755, true, true);
}
// Make sure it's an image file
if (!$this->isImage() || !is_file($this->get('fullPath'))) {
return false;
}
if (!Filesystem::copy($this->get('fullPath'), $target . DS . $hashed)) {
return false;
}
// Resize the image if necessary
$hi = new \Hubzero\Image\Processor($target . DS . $hashed);
$square = $render == 'thumb' ? true : false;
$hi->resize($maxWidth, false, false, $square);
$hi->save($target . DS . $hashed);
$image = $target . DS . $hashed;
}
// Return image
if ($get == 'localPath') {
return str_replace(PATH_APP, '', $image);
} elseif ($get == 'fullPath') {
return $image;
} elseif ($get == 'url') {
return Route::url('index.php?option=com_projects&alias=' . $model->get('alias') . '&controller=media&media=' . urlencode(basename($image)));
}
return basename($image);
}
示例15: deletefileTask
/**
* Deletes a file
*
* @return void
*/
public function deletefileTask()
{
// Check for request forgeries
Request::checkToken('get');
// Incoming directory (this should be a path built from a resource ID and its creation year/month)
$listdir = Request::getVar('listdir', '');
if (!$listdir) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_LISTDIR'));
$this->displayTask();
return;
}
// Make sure the listdir follows YYYY/MM/#
$parts = explode('/', $listdir);
if (count($parts) < 3) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_DIRECTORY_NOT_FOUND'));
$this->displayTask();
return;
}
// Incoming sub-directory
$subdir = Request::getVar('subdir', '');
// Build the path
$path = Utilities::buildUploadPath($listdir, $subdir);
// Incoming file to delete
$file = Request::getVar('delFile', '');
if (!$file) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_NO_FILE'));
$this->displayTask();
return;
}
// Check if the file even exists
if (!file_exists($path . DS . $file) or !$file) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_FILE_NOT_FOUND'));
} else {
// Attempt to delete the file
if (!\Filesystem::delete($path . DS . $file)) {
$this->setError(Lang::txt('COM_RESOURCES_ERROR_UNABLE_TO_DELETE_FILE'));
}
}
// Push through to the media view
$this->displayTask();
}