FileManager.php
2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
namespace common\helpers;
/**
* 极办公系统 文件资源管理器
* Class FileManager
* @package app\common\helpers
*/
class FileManager
{
private static $VOICE_ROOT_PATH = 'call_voice/'; // 录音文件路径
private static $TEMP_ROOT_PATH = 'tmp/'; // 临时目录
private static $INVOICE_ROOT_PATH = 'invoice/'; // 电子发票
public static function getUrl($path)
{
if(empty($path)) {
return '';
}
return FileServiceHelper::getUrl($path);
}
/**
* 添加上传图片
* @param $tmpPath
* @param $savePath
*/
public static function add($tmpPath, $savePath)
{
return FileServiceHelper::add($tmpPath, $savePath);
}
/**
* 替换图片
* @param $oldPath
* @param $newPath
* @param $tmpPath
*/
public static function replace($oldPath, $newPath, $tmpPath)
{
return FileServiceHelper::replace($oldPath, $newPath, $tmpPath);
}
/**
* 移动图片存放位置
* @param $oldPath
* @param $newPath
* @return mixed
*/
public static function move($oldPath, $newPath)
{
FileServiceHelper::move($oldPath, $newPath);
}
/**
* 删除旧图片
* @param $path
*/
public static function delete($path){
FileServiceHelper::delete($path);
}
/**
* 获取电子发票pdf文件存储路径
* @param $sid
* @param string $suffix
* @return string
*/
public static function getInvoicePdfPath($sid, $suffix = "pdf")
{
$imageName = $sid . '.' . $suffix;
$basePath = self::$INVOICE_ROOT_PATH . date("Ymd");
$savePath = $basePath . '/' . $imageName;
return $savePath;
}
/** 组织声音文件的路径
* @param $orderId
* @param $recordId
* @param string $suffix
* @return string
*/
public static function getOrderCallVoice($orderId, $recordId, $suffix = "wav")
{
$fileName = $recordId . '.' . $suffix;
$basePath = self::$VOICE_ROOT_PATH . $orderId;
$savePath = $basePath . '/' . $fileName;
return $savePath;
}
/** 删除临时语音文件
* @param $tmpPath
*/
public static function deleteLocalTmpVoice($tmpPath)
{
if (is_file($tmpPath)) {
if (unlink($tmpPath)) {
return true;
}
}
return false;
}
}