Esempio n. 1
0
 public static function delete($path)
 {
     //修正一下 Path
     $path = realpath($path);
     //目录
     $dirname = dirname($path);
     //文件
     $file = substr($path, strrpos($path, '/') + 1);
     //不进行删除, 增加 . 进行隐藏即可
     $new_path = strtr('%dirname/.%file', ['%dirname' => $dirname, '%file' => $file]);
     if (file_exists($new_path)) {
         $dirname = dirname($new_path) . '/';
         $info = \App\NFS::pathinfo($new_path);
         $extension = $info['extension'] ? '.' . $info['extension'] : '';
         $name = substr($file, 0, strrpos($file, '.') ?: strlen($file));
         $suffix_count = 2;
         do {
             $file_name = $name . '(' . $suffix_count . ')' . $extension;
             $new_path = $dirname . '.' . $file_name;
             ++$suffix_count;
         } while (file_exists($new_path));
     }
     return rename($path, $new_path);
 }
Esempio n. 2
0
 public function upload($project_id, Request $request)
 {
     $user = \Session::get('user');
     if (!$user->can('项目文件管理')) {
         abort(401);
     }
     $project = Project::find($project_id);
     if ($request->hasFile('file')) {
         $path = $request->input('path');
         $file = $request->file('file')->getClientOriginalName();
         $full_path = \App\NFS::full_path($project, $path);
         $full_file = \App\NFS::full_path($project, $path . '/' . $file);
         if (file_exists($full_file)) {
             $dirname = dirname($full_file) . '/';
             $info = \App\NFS::pathinfo($full_file);
             $extension = $info['extension'] ? '.' . $info['extension'] : '';
             $name = substr($file, 0, strrpos($file, '.') ?: strlen($file));
             $suffix_count = 2;
             do {
                 $file_name = $name . '(' . $suffix_count . ')' . $extension;
                 $full_file = $dirname . $file_name;
                 ++$suffix_count;
             } while (file_exists($full_file));
         }
         $file = substr($full_file, strrpos($full_file, '/') + 1);
         \Log::notice(strtr('文件上传: 用户(%name[%id]) 在路径 %path 中上传了文件 %file', ['%name' => $user->name, '%id' => $user->id, '%path' => $full_path, '%file' => $file]));
         $request->file('file')->move($full_path, $file);
         return redirect()->back()->with('message_content', '上传成功!')->with('message_type', 'info');
     } else {
         return redirect()->back()->with('message_content', '上传失败')->with('message_type', 'danger');
     }
 }
Esempio n. 3
0
 public function init_nfs()
 {
     \App\NFS::nfs_init($this);
 }