本文整理汇总了PHP中UploadBase::cleanupTempFile方法的典型用法代码示例。如果您正苦于以下问题:PHP UploadBase::cleanupTempFile方法的具体用法?PHP UploadBase::cleanupTempFile怎么用?PHP UploadBase::cleanupTempFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UploadBase
的用法示例。
在下文中一共展示了UploadBase::cleanupTempFile方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* Special page entry point
*/
public function execute($par)
{
global $wgUser, $wgOut;
$this->setHeaders();
$this->outputHeader();
# Check uploading enabled
if (!UploadBase::isEnabled()) {
$wgOut->showErrorPage('uploaddisabled', 'uploaddisabledtext');
return;
}
# Check permissions
global $wgGroupPermissions;
$permissionRequired = UploadBase::isAllowed($wgUser);
if ($permissionRequired !== true) {
if (!$wgUser->isLoggedIn() && ($wgGroupPermissions['user']['upload'] || $wgGroupPermissions['autoconfirmed']['upload'])) {
// Custom message if logged-in users without any special rights can upload
$wgOut->showErrorPage('uploadnologin', 'uploadnologintext');
} else {
$wgOut->permissionRequired($permissionRequired);
}
return;
}
# Check blocks
if ($wgUser->isBlocked()) {
$wgOut->blockedPage();
return;
}
# Check whether we actually want to allow changing stuff
if (wfReadOnly()) {
$wgOut->readOnlyPage();
return;
}
# Unsave the temporary file in case this was a cancelled upload
if ($this->mCancelUpload) {
if (!$this->unsaveUploadedFile()) {
# Something went wrong, so unsaveUploadedFile showed a warning
return;
}
}
# Process upload or show a form
if ($this->mTokenOk && !$this->mCancelUpload && ($this->mUpload && $this->mUploadClicked)) {
$this->processUpload();
} else {
# Backwards compatibility hook
if (!wfRunHooks('UploadForm:initial', array(&$this))) {
wfDebug("Hook 'UploadForm:initial' broke output of the upload form");
return;
}
$this->showUploadForm($this->getUploadForm());
}
# Cleanup
if ($this->mUpload) {
$this->mUpload->cleanupTempFile();
}
}
示例2: execute
/**
* Special page entry point
*/
public function execute( $par ) {
$this->setHeaders();
$this->outputHeader();
# Check uploading enabled
if ( !UploadBase::isEnabled() ) {
throw new ErrorPageError( 'uploaddisabled', 'uploaddisabledtext' );
}
# Check permissions
$user = $this->getUser();
$permissionRequired = UploadBase::isAllowed( $user );
if ( $permissionRequired !== true ) {
throw new PermissionsError( $permissionRequired );
}
# Check blocks
if ( $user->isBlocked() ) {
throw new UserBlockedError( $user->getBlock() );
}
# Check whether we actually want to allow changing stuff
$this->checkReadOnly();
$this->loadRequest();
# Unsave the temporary file in case this was a cancelled upload
if ( $this->mCancelUpload ) {
if ( !$this->unsaveUploadedFile() ) {
# Something went wrong, so unsaveUploadedFile showed a warning
return;
}
}
# Process upload or show a form
if (
$this->mTokenOk && !$this->mCancelUpload &&
( $this->mUpload && $this->mUploadClicked )
) {
$this->processUpload();
} else {
# Backwards compatibility hook
if ( !wfRunHooks( 'UploadForm:initial', array( &$this ) ) ) {
wfDebug( "Hook 'UploadForm:initial' broke output of the upload form" );
return;
}
$this->showUploadForm( $this->getUploadForm() );
}
# Cleanup
if ( $this->mUpload ) {
$this->mUpload->cleanupTempFile();
}
}
示例3: execute
public function execute()
{
// Check whether upload is enabled
if (!UploadBase::isEnabled()) {
$this->dieUsageMsg('uploaddisabled');
}
$user = $this->getUser();
// Parameter handling
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
// Check if async mode is actually supported (jobs done in cli mode)
$this->mParams['async'] = $this->mParams['async'] && $this->getConfig()->get('EnableAsyncUploads');
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName('file');
$this->mParams['chunk'] = $request->getFileName('chunk');
// Copy the session key to the file key, for backward compatibility.
if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
$this->mParams['filekey'] = $this->mParams['sessionkey'];
}
// Select an upload module
try {
if (!$this->selectUploadModule()) {
return;
// not a true upload, but a status request or similar
} elseif (!isset($this->mUpload)) {
$this->dieUsage('No upload module set', 'nomodule');
}
} catch (UploadStashException $e) {
// XXX: don't spam exception log
$this->handleStashException($e);
}
// First check permission to upload
$this->checkPermissions($user);
// Fetch the file (usually a no-op)
/** @var $status Status */
$status = $this->mUpload->fetchFile();
if (!$status->isGood()) {
$errors = $status->getErrorsArray();
$error = array_shift($errors[0]);
$this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
}
// Check if the uploaded file is sane
if ($this->mParams['chunk']) {
$maxSize = UploadBase::getMaxUploadSize();
if ($this->mParams['filesize'] > $maxSize) {
$this->dieUsage('The file you submitted was too large', 'file-too-large');
}
if (!$this->mUpload->getTitle()) {
$this->dieUsage('Invalid file title supplied', 'internal-error');
}
} elseif ($this->mParams['async'] && $this->mParams['filekey']) {
// defer verification to background process
} else {
wfDebug(__METHOD__ . " about to verify\n");
$this->verifyUpload();
}
// Check if the user has the rights to modify or overwrite the requested title
// (This check is irrelevant if stashing is already requested, since the errors
// can always be fixed by changing the title)
if (!$this->mParams['stash']) {
$permErrors = $this->mUpload->verifyTitlePermissions($user);
if ($permErrors !== true) {
$this->dieRecoverableError($permErrors[0], 'filename');
}
}
// Get the result based on the current upload context:
try {
$result = $this->getContextResult();
if ($result['result'] === 'Success') {
$result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
}
} catch (UploadStashException $e) {
// XXX: don't spam exception log
$this->handleStashException($e);
}
$this->getResult()->addValue(null, $this->getModuleName(), $result);
// Cleanup any temporary mess
$this->mUpload->cleanupTempFile();
}
示例4: execute
public function execute()
{
// Check whether upload is enabled
if (!UploadBase::isEnabled()) {
$this->dieUsageMsg('uploaddisabled');
}
$user = $this->getUser();
// Parameter handling
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName('file');
$this->mParams['chunk'] = $request->getFileName('chunk');
// Copy the session key to the file key, for backward compatibility.
if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
$this->mParams['filekey'] = $this->mParams['sessionkey'];
}
// Select an upload module
if (!$this->selectUploadModule()) {
// This is not a true upload, but a status request or similar
return;
}
if (!isset($this->mUpload)) {
$this->dieUsage('No upload module set', 'nomodule');
}
// First check permission to upload
$this->checkPermissions($user);
// Fetch the file
$status = $this->mUpload->fetchFile();
if (!$status->isGood()) {
$errors = $status->getErrorsArray();
$error = array_shift($errors[0]);
$this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
}
// Check if the uploaded file is sane
if ($this->mParams['chunk']) {
$maxSize = $this->mUpload->getMaxUploadSize();
if ($this->mParams['filesize'] > $maxSize) {
$this->dieUsage('The file you submitted was too large', 'file-too-large');
}
} else {
$this->verifyUpload();
}
// Check if the user has the rights to modify or overwrite the requested title
// (This check is irrelevant if stashing is already requested, since the errors
// can always be fixed by changing the title)
if (!$this->mParams['stash']) {
$permErrors = $this->mUpload->verifyTitlePermissions($user);
if ($permErrors !== true) {
$this->dieRecoverableError($permErrors[0], 'filename');
}
}
// Get the result based on the current upload context:
$result = $this->getContextResult();
if ($result['result'] === 'Success') {
$result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
}
$this->getResult()->addValue(null, $this->getModuleName(), $result);
// Cleanup any temporary mess
$this->mUpload->cleanupTempFile();
}
示例5: execute
public function execute()
{
global $wgUser;
// Check whether upload is enabled
if (!UploadBase::isEnabled()) {
$this->dieUsageMsg('uploaddisabled');
}
// Parameter handling
$this->mParams = $this->extractRequestParams();
$request = $this->getMain()->getRequest();
// Add the uploaded file to the params array
$this->mParams['file'] = $request->getFileName('file');
// Copy the session key to the file key, for backward compatibility.
if (!$this->mParams['filekey'] && $this->mParams['sessionkey']) {
$this->mParams['filekey'] = $this->mParams['sessionkey'];
}
// Select an upload module
if (!$this->selectUploadModule()) {
// This is not a true upload, but a status request or similar
return;
}
if (!isset($this->mUpload)) {
$this->dieUsage('No upload module set', 'nomodule');
}
// First check permission to upload
$this->checkPermissions($wgUser);
// Fetch the file
$status = $this->mUpload->fetchFile();
if (!$status->isGood()) {
$errors = $status->getErrorsArray();
$error = array_shift($errors[0]);
$this->dieUsage('Error fetching file from remote source', $error, 0, $errors[0]);
}
// Check if the uploaded file is sane
$this->verifyUpload();
// Check if the user has the rights to modify or overwrite the requested title
// (This check is irrelevant if stashing is already requested, since the errors
// can always be fixed by changing the title)
if (!$this->mParams['stash']) {
$permErrors = $this->mUpload->verifyTitlePermissions($wgUser);
if ($permErrors !== true) {
$this->dieRecoverableError($permErrors[0], 'filename');
}
}
// Prepare the API result
$result = array();
$warnings = $this->getApiWarnings();
if ($warnings) {
$result['result'] = 'Warning';
$result['warnings'] = $warnings;
// in case the warnings can be fixed with some further user action, let's stash this upload
// and return a key they can use to restart it
try {
$result['filekey'] = $this->performStash();
$result['sessionkey'] = $result['filekey'];
// backwards compatibility
} catch (MWException $e) {
$result['warnings']['stashfailed'] = $e->getMessage();
}
} elseif ($this->mParams['stash']) {
// Some uploads can request they be stashed, so as not to publish them immediately.
// In this case, a failure to stash ought to be fatal
try {
$result['result'] = 'Success';
$result['filekey'] = $this->performStash();
$result['sessionkey'] = $result['filekey'];
// backwards compatibility
} catch (MWException $e) {
$this->dieUsage($e->getMessage(), 'stashfailed');
}
} else {
// This is the most common case -- a normal upload with no warnings
// $result will be formatted properly for the API already, with a status
$result = $this->performUpload();
}
if ($result['result'] === 'Success') {
$result['imageinfo'] = $this->mUpload->getImageInfo($this->getResult());
}
$this->getResult()->addValue(null, $this->getModuleName(), $result);
// Cleanup any temporary mess
$this->mUpload->cleanupTempFile();
}