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


PHP FileSystem::clean_path方法代码示例

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


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

示例1: uploadFinished

 /**
  * this is called as soon as uploads have finished.
  * takes care of moving them to the right folder
  *
  * @return string the directory to move to
  */
 public static function uploadFinished($tempPath, $tempWebPath, $data, $uploadId, $fileInfos, $response)
 {
     $path = $data['path'];
     $webPath = $data['webPath'];
     //we remember the names of the uploaded files here. they are stored in the session afterwards,
     //so we can later display them highlighted.
     $arrFiles = array();
     //rename files, delete unwanted
     $arrFilesToRename = array();
     //used to remember the files we need to rename
     $h = opendir($tempPath);
     if ($h) {
         while (false !== ($file = readdir($h))) {
             //delete potentially malicious files
             // TODO: this is probably an overhead, because the uploader might already to this. doesn't it?
             if (!\FWValidator::is_file_ending_harmless($file)) {
                 @unlink($file);
                 continue;
             }
             if (self::isIllegalFileName($file)) {
                 $response->addMessage(\Cx\Core_Modules\Upload\Controller\UploadResponse::STATUS_ERROR, "You are not able to create the requested file.");
                 \Cx\Lib\FileSystem\FileSystem::delete_file($tempPath . '/' . $file);
                 continue;
             }
             //skip . and ..
             if ($file == '.' || $file == '..') {
                 continue;
             }
             //clean file name
             $newName = $file;
             \Cx\Lib\FileSystem\FileSystem::clean_path($newName);
             //check if file needs to be renamed
             if (file_exists($path . $newName)) {
                 $info = pathinfo($newName);
                 $exte = $info['extension'];
                 $exte = !empty($exte) ? '.' . $exte : '';
                 $part1 = $info['filename'];
                 if (empty($_REQUEST['uploadForceOverwrite']) || !intval($_REQUEST['uploadForceOverwrite'] > 0)) {
                     $newName = $part1 . '_' . time() . $exte;
                 }
             }
             //if the name has changed, the file needs to be renamed afterwards
             if ($newName != $file) {
                 $arrFilesToRename[$file] = $newName;
             }
             array_push($arrFiles, $newName);
         }
     }
     //rename files where needed
     foreach ($arrFilesToRename as $oldName => $newName) {
         rename($tempPath . '/' . $oldName, $tempPath . '/' . $newName);
     }
     //remeber the uploaded files
     $files = $_SESSION["media_upload_files_{$uploadId}"];
     $_SESSION["media_upload_files_{$uploadId}"] = array_merge($arrFiles, $files ? $files->toArray() : []);
     /* unwanted files have been deleted, unallowed filenames corrected.
        we can now simply return the desired target path, as only valid
        files are present in $tempPath                                   */
     return array($data['path'], $data['webPath']);
 }
开发者ID:Cloudrexx,项目名称:cloudrexx,代码行数:66,代码来源:MediaLibrary.class.php


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