当前位置: 首页>>代码示例>>PHP>>正文


PHP IOHelper::deleteFile方法代码示例

本文整理汇总了PHP中IOHelper::deleteFile方法的典型用法代码示例。如果您正苦于以下问题:PHP IOHelper::deleteFile方法的具体用法?PHP IOHelper::deleteFile怎么用?PHP IOHelper::deleteFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IOHelper的用法示例。


在下文中一共展示了IOHelper::deleteFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: actionPrepareForCrop

 /**
  * Prepare asset for cropping.
  */
 public function actionPrepareForCrop()
 {
     $this->requireAjaxRequest();
     $elementId = craft()->request->getParam('elementId');
     // Get the asset file
     $asset = craft()->assets->getFileById($elementId);
     $source = $asset->getSource();
     $sourceType = $source->getSourceType();
     $file = $sourceType->getLocalCopy($asset);
     try {
         // Test if we will be able to perform image actions on this image
         if (!craft()->images->checkMemoryForImage($file)) {
             IOHelper::deleteFile($file);
             $this->returnErrorJson(Craft::t('The selected image is too large.'));
         }
         // Scale to fit 500x500 for fitting in CP modal
         craft()->images->loadImage($file)->scaleToFit(500, 500, false)->saveAs($file);
         list($width, $height) = ImageHelper::getImageSize($file);
         // If the file is in the format badscript.php.gif perhaps.
         if ($width && $height) {
             $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => $asset->url, 'width' => $width, 'height' => $height, 'fileName' => $asset->filename));
             $this->returnJson(array('html' => $html));
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
 }
开发者ID:boboldehampsink,项目名称:cropassets,代码行数:30,代码来源:CropAssetsController.php

示例2: download

 /**
  * Download zipfile.
  *
  * @param array  $files
  * @param string $filename
  *
  * @return string
  */
 public function download($files, $filename)
 {
     // Get assets
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $files;
     $criteria->limit = null;
     $assets = $criteria->find();
     // Set destination zip
     $destZip = craft()->path->getTempPath() . $filename . '_' . time() . '.zip';
     // Create zip
     $zip = new \ZipArchive();
     // Open zip
     if ($zip->open($destZip, $zip::CREATE) === true) {
         // Loop through assets
         foreach ($assets as $asset) {
             // Get asset source
             $source = $asset->getSource();
             // Get asset source type
             $sourceType = $source->getSourceType();
             // Get asset file
             $file = $sourceType->getLocalCopy($asset);
             // Add to zip
             $zip->addFromString($asset->filename, IOHelper::getFileContents($file));
             // Remove the file
             IOHelper::deleteFile($file);
         }
         // Close zip
         $zip->close();
         // Return zip destination
         return $destZip;
     }
     // Something went wrong
     throw new Exception(Craft::t('Failed to generate the zipfile'));
 }
开发者ID:boboldehampsink,项目名称:zipassets,代码行数:42,代码来源:ZipAssetsService.php

示例3: actionCropLogo

 /**
  * Crop user photo.
  */
 public function actionCropLogo()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     try {
         $x1 = craft()->request->getRequiredPost('x1');
         $x2 = craft()->request->getRequiredPost('x2');
         $y1 = craft()->request->getRequiredPost('y1');
         $y2 = craft()->request->getRequiredPost('y2');
         $source = craft()->request->getRequiredPost('source');
         // Strip off any querystring info, if any.
         if (($qIndex = strpos($source, '?')) !== false) {
             $source = substr($source, 0, strpos($source, '?'));
         }
         $imagePath = craft()->path->getTempUploadsPath() . $source;
         if (IOHelper::fileExists($imagePath) && craft()->images->setMemoryForImage($imagePath)) {
             $targetPath = craft()->path->getStoragePath() . 'logo/';
             IOHelper::ensureFolderExists($targetPath);
             IOHelper::clearFolder($targetPath);
             craft()->images->loadImage($imagePath)->crop($x1, $x2, $y1, $y2)->scaleToFit(300, 300, false)->saveAs($targetPath . $source);
             IOHelper::deleteFile($imagePath);
             $html = craft()->templates->render('settings/general/_logo');
             $this->returnJson(array('html' => $html));
         }
         IOHelper::deleteFile($imagePath);
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('Something went wrong when processing the logo.'));
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:33,代码来源:RebrandController.php

示例4: actionDownloadFile

 /**
  * Downloads a file and cleans up old temporary assets
  */
 public function actionDownloadFile()
 {
     // Clean up temp assets files that are more than a day old
     $fileResults = array();
     $files = IOHelper::getFiles(craft()->path->getTempPath(), true);
     foreach ($files as $file) {
         $lastModifiedTime = IOHelper::getLastTimeModified($file, true);
         if (substr(IOHelper::getFileName($file, false, true), 0, 6) === "assets" && DateTimeHelper::currentTimeStamp() - $lastModifiedTime->getTimestamp() >= 86400) {
             IOHelper::deleteFile($file);
         }
     }
     // Sort out the file we want to download
     $id = craft()->request->getParam('id');
     $criteria = craft()->elements->getCriteria(ElementType::Asset);
     $criteria->id = $id;
     $asset = $criteria->first();
     if ($asset) {
         // Get a local copy of the file
         $sourceType = craft()->assetSources->getSourceTypeById($asset->sourceId);
         $localCopy = $sourceType->getLocalCopy($asset);
         // Send it to the browser
         craft()->request->sendFile($asset->filename, IOHelper::getFileContents($localCopy), array('forceDownload' => true));
         craft()->end();
     }
 }
开发者ID:supercool,项目名称:Tools,代码行数:28,代码来源:SupercoolToolsController.php

示例5: tearDownAfterClass

 /**
  * {@inheritdoc}
  */
 public static function tearDownAfterClass()
 {
     // Remove test file
     $file = __DIR__ . '/../translations/test.php';
     IOHelper::deleteFile($file);
     // Tear down parent
     parent::tearDownAfterClass();
 }
开发者ID:boboldehampsink,项目名称:translate,代码行数:11,代码来源:TranslateServiceTest.php

示例6: deleteTempFiles

 private function deleteTempFiles($fileName)
 {
     $tempPath = craft()->path->getTempPath();
     IOHelper::deleteFile($tempPath . $fileName, true);
     $info = pathinfo($fileName);
     $fileNameNoExtension = $info['filename'];
     $ext = $info['extension'];
     IOHelper::deleteFile($tempPath . $fileNameNoExtension . '-temp.' . $ext, true);
 }
开发者ID:revescom11,项目名称:AviaryImageEditor,代码行数:9,代码来源:FruitAviaryImageEditorService.php

示例7: resize

 public function resize($sourceId, $path, $width, $height)
 {
     try {
         $settings = craft()->imageResizer->getSettings();
         $image = craft()->images->loadImage($path);
         $filename = basename($path);
         // We can have settings globally, or per asset source. Check!
         // Our maximum width/height for assets from plugin settings
         $imageWidth = craft()->imageResizer->getSettingForAssetSource($sourceId, 'imageWidth');
         $imageHeight = craft()->imageResizer->getSettingForAssetSource($sourceId, 'imageHeight');
         // Allow for overrides passed on-demand
         $imageWidth = $width ? $width : $imageWidth;
         $imageHeight = $height ? $height : $imageHeight;
         // Lets check to see if this image needs resizing. Split into two steps to ensure
         // proper aspect ratio is preserved and no upscaling occurs.
         $hasResized = false;
         if ($image->getWidth() > $imageWidth) {
             $hasResized = true;
             $this->_resizeImage($image, $imageWidth, null);
         }
         if ($image->getHeight() > $imageHeight) {
             $hasResized = true;
             $this->_resizeImage($image, null, $imageHeight);
         }
         if ($hasResized) {
             // Set image quality - but normalise (for PNG)!
             $image->setQuality(craft()->imageResizer->getImageQuality($filename));
             // If we're checking for larger images
             if ($settings->skipLarger) {
                 // Save this resized image in a temporary location - we need to test filesize difference
                 $tempPath = AssetsHelper::getTempFilePath($filename);
                 $image->saveAs($tempPath);
                 clearstatcache();
                 // Lets check to see if this resize resulted in a larger file - revert if so.
                 if (filesize($tempPath) < filesize($path)) {
                     $image->saveAs($path);
                     // Its a smaller file - properly save
                 } else {
                     ImageResizerPlugin::log('Did not resize ' . $filename . ' as it would result in a larger file.', LogLevel::Info, true);
                 }
                 // Delete our temp file we test filesize with
                 IOHelper::deleteFile($tempPath, true);
             } else {
                 $image->saveAs($path);
             }
         }
         return true;
     } catch (\Exception $e) {
         ImageResizerPlugin::log($e->getMessage(), LogLevel::Error, true);
         return false;
     }
 }
开发者ID:engram-design,项目名称:ImageResizer,代码行数:52,代码来源:ImageResizer_ResizeService.php

示例8: performAction

 /**
  * Performs the tool's action.
  *
  * @param array $params
  * @return array
  */
 public function performAction($params = array())
 {
     $file = craft()->db->backup();
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:20,代码来源:DbBackupTool.php

示例9: safeUp

 /**
  * Any migration code in here is wrapped inside of a transaction.
  *
  * @return bool
  */
 public function safeUp()
 {
     $filesToDelete = array('elementtypes/MatrixRecordElementType.php', 'etc/assets/fileicons/56.png', 'etc/console/commands/MigrateCommand.php', 'etc/console/commands/QuerygenCommand.php', 'migrations/m130917_000000_drop_users_enctype.php', 'migrations/m130917_000001_big_names_and_handles.php', 'migrations/m130917_000002_entry_types.php', 'migrations/m130917_000003_section_types.php', 'migrations/m131105_000000_content_column_field_prefixes.php', 'migrations/m131105_000001_add_missing_content_and_i18n_rows.php', 'migrations/m131105_000001_element_content.php', 'migrations/m131105_000002_schema_version.php', 'migrations/m131105_000003_field_contexts.php', 'migrations/m131105_000004_matrix.php', 'migrations/m131105_000004_matrix_blocks.php', 'migrations/m131105_000005_correct_tag_field_layouts.php', 'migrations/m131105_000006_remove_gethelp_widget_for_non_admins.php', 'migrations/m131105_000007_new_relation_column_names.php', 'migrations/m131105_000008_add_values_for_unknown_asset_kinds.php', 'models/MatrixRecordModel.php', 'models/MatrixRecordTypeModel.php', 'models/TagSetModel.php', 'records/EntryLocaleRecord.php', 'records/MatrixRecordRecord.php', 'records/MatrixRecordTypeRecord.php', 'records/StructuredEntryRecord.php', 'records/TagSetRecord.php', 'resources/images/whats-new/entrytypes.png', 'resources/images/whats-new/single.png', 'resources/images/whats-new/structure.png', 'resources/js/compressed/dashboard.js', 'resources/js/compressed/dashboard.min.map', 'resources/js/dashboard.js', 'templates/assets/_nav_folder.html', 'templates/users/_edit/_userphoto.html', 'templates/users/_edit/account.html', 'templates/users/_edit/admin.html', 'templates/users/_edit/layout.html', 'templates/users/_edit/profile.html', 'translations/fr_fr.php');
     $appPath = craft()->path->getAppPath();
     foreach ($filesToDelete as $fileToDelete) {
         if (IOHelper::fileExists($appPath . $fileToDelete)) {
             $fullPath = $appPath . $fileToDelete;
             Craft::log('Deleting file: ' . $fullPath . ' because it is not supposed to exist.', LogLevel::Info, true);
             IOHelper::deleteFile($appPath . $fileToDelete);
         } else {
             Craft::log('File: ' . $fileToDelete . ' does not exist.  Good.', LogLevel::Info, true);
         }
     }
     return true;
 }
开发者ID:scisahaha,项目名称:generator-craft,代码行数:20,代码来源:m140401_000000_delete_the_deleted_files.php

示例10: getUrl

 /**
  * Get cropped image url.
  *
  * @param null|array $settings
  *
  * @return string
  */
 public function getUrl($settings = null)
 {
     // Get image
     $file = $this->getFile();
     // Do the cropping
     $this->applyCrop($file, $settings);
     // Get base64 of crop
     $base64 = $this->getBase64($file);
     // Get mime
     $mime = IOHelper::getMimeType($file);
     // Delete the temp image
     IOHelper::deleteFile($file);
     // Return base64 string
     return 'data:' . $mime . ';base64,' . $base64;
 }
开发者ID:boboldehampsink,项目名称:cropassets,代码行数:22,代码来源:CropAssetsModel.php

示例11: performAction

 /**
  * @inheritDoc ITool::performAction()
  *
  * @param array $params
  *
  * @return array
  */
 public function performAction($params = array())
 {
     // In addition to the default tables we want to ignore data in, we also don't care about data in the session
     // table in this tools' case.
     $file = craft()->db->backup(array('sessions'));
     if (IOHelper::fileExists($file) && isset($params['downloadBackup']) && (bool) $params['downloadBackup']) {
         $destZip = craft()->path->getTempPath() . IOHelper::getFileName($file, false) . '.zip';
         if (IOHelper::fileExists($destZip)) {
             IOHelper::deleteFile($destZip, true);
         }
         IOHelper::createFile($destZip);
         if (Zip::add($destZip, $file, craft()->path->getDbBackupPath())) {
             return array('backupFile' => IOHelper::getFileName($destZip, false));
         }
     }
 }
开发者ID:kant312,项目名称:sop,代码行数:23,代码来源:DbBackupTool.php

示例12: compress

 /**
  * @param $source
  * @param $destZip
  *
  * @return bool 'true' if the zip was successfully created, 'false' if not.
  */
 public static function compress($source, $destZip)
 {
     $source = IOHelper::normalizePathSeparators($source);
     $destZip = IOHelper::normalizePathSeparators($destZip);
     if (!IOHelper::folderExists($source) && !IOHelper::fileExists($destZip)) {
         Craft::log('Tried to zip the contents of ' . $source . ' to ' . $destZip . ', but the source path does not exist.', LogLevel::Error);
         return false;
     }
     if (IOHelper::fileExists($destZip)) {
         IOHelper::deleteFile($destZip);
     }
     IOHelper::createFile($destZip);
     craft()->config->maxPowerCaptain();
     $zip = static::_getZipInstance($destZip);
     return $zip->zip(IOHelper::getRealPath($source), IOHelper::getRealPath($destZip));
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:22,代码来源:Zip.php

示例13: deleteExpiredCache

 /**
  * Based on the cache's hashed base, attempts to delete any older versions of same name.
  */
 public function deleteExpiredCache()
 {
     MinimeePlugin::log(Craft::t('Minimee is attempting to delete expired caches.'));
     $files = IOHelper::getFiles($this->settings->cachePath);
     foreach ($files as $file) {
         // skip self
         if ($file === $this->makePathToCacheFilename()) {
             continue;
         }
         if (strpos($file, $this->makePathToHashOfCacheBase()) === 0) {
             MinimeePlugin::log(Craft::t('Minimee is attempting to delete file: ') . $file);
             // suppress errors by passing true as second parameter
             IOHelper::deleteFile($file, true);
         }
     }
 }
开发者ID:speder,项目名称:craft.minimee,代码行数:19,代码来源:MinimeeService.php

示例14: actionDownload

 public function actionDownload()
 {
     $segments = craft()->request->segments;
     $file = craft()->assets->getFileById((int) end($segments));
     $user = craft()->userSession->getUser();
     if ($file && $user) {
         $source = $file->getSource();
         $sourceType = $source->getSourceType();
         $download = $sourceType->getLocalCopy($file);
         header('Content-type: ' . $file->getMimeType());
         header('Content-Disposition: attachment; filename="' . $file->filename . '"');
         echo file_get_contents($download);
         IOHelper::deleteFile($download);
     } else {
         $this->redirect("404");
     }
 }
开发者ID:brammittendorff,项目名称:CraftCms-Restricted-Assets-Plugin,代码行数:17,代码来源:RestrictedAssetsController.php

示例15: actionDownload

 /**
  * Download zip.
  */
 public function actionDownload()
 {
     // Get wanted filename
     $filename = craft()->request->getRequiredParam('filename');
     // Get file id's
     $files = craft()->request->getRequiredParam('files');
     // Generate zipfile
     $zipfile = craft()->zipAssets->download($files, $filename);
     // Get zip filename
     $zipname = IOHelper::getFileName($zipfile);
     // Get zip filecontents
     $zip = IOHelper::getFileContents($zipfile);
     // Delete zipfile
     IOHelper::deleteFile($zipfile);
     // Download it
     craft()->request->sendFile($zipname, $zip, array('forceDownload' => true));
 }
开发者ID:khalwat,项目名称:zipassets,代码行数:20,代码来源:ZipAssetsController.php


注:本文中的IOHelper::deleteFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。