【调度系统】广东民航医疗快线调度系统源代码
wlzboy
2025-08-14 b3f8789cf8bf0d934f8431b1d7b564a756576b4b
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<?php
header('Content-Type: application/json; charset=utf-8');
 
// 设置错误报告
error_reporting(E_ALL);
ini_set('display_errors', 1);
 
// 允许跨域请求(如果需要)
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST');
header('Access-Control-Allow-Headers: Content-Type');
 
// 检查请求方法
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
    echo json_encode([
        'success' => false,
        'message' => '只支持POST请求'
    ]);
    exit;
}
 
// 获取参数
$uploadFileName = isset($_POST['uploadFileName']) ? $_POST['uploadFileName'] : '';
$file = isset($_FILES['file']) ? $_FILES['file'] : null;
 
// 验证参数
if (empty($uploadFileName)) {
    echo json_encode([
        'success' => false,
        'message' => 'uploadFileName参数不能为空'
    ]);
    exit;
}
 
if (!$file || $file['error'] !== UPLOAD_ERR_OK) {
    $errorMessage = '文件上传失败';
    if ($file) {
        switch ($file['error']) {
            case UPLOAD_ERR_INI_SIZE:
                $errorMessage = '文件大小超过php.ini限制';
                break;
            case UPLOAD_ERR_FORM_SIZE:
                $errorMessage = '文件大小超过表单限制';
                break;
            case UPLOAD_ERR_PARTIAL:
                $errorMessage = '文件只有部分被上传';
                break;
            case UPLOAD_ERR_NO_FILE:
                $errorMessage = '没有文件被上传';
                break;
            case UPLOAD_ERR_NO_TMP_DIR:
                $errorMessage = '找不到临时文件夹';
                break;
            case UPLOAD_ERR_CANT_WRITE:
                $errorMessage = '文件写入失败';
                break;
        }
    }
    echo json_encode([
        'success' => false,
        'message' => $errorMessage
    ]);
    exit;
}
 
// 验证文件类型(可选)
$allowedTypes = ['image/jpeg', 'image/jpg', 'image/png', 'image/gif', 'application/pdf', 'application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document'];
if (!in_array($file['type'], $allowedTypes)) {
    echo json_encode([
        'success' => false,
        'message' => '不支持的文件类型:' . $file['type']
    ]);
    exit;
}
 
// 验证文件大小(限制为10MB)
$maxFileSize = 10 * 1024 * 1024; // 10MB
if ($file['size'] > $maxFileSize) {
    echo json_encode([
        'success' => false,
        'message' => '文件大小超过限制(最大10MB)'
    ]);
    exit;
}
 
try {
    // 创建年月目录
    $yearMonth = date('Ym');
    $uploadDir = "../upload/{$yearMonth}/";
    
    // 如果目录不存在则创建
    if (!is_dir($uploadDir)) {
        if (!mkdir($uploadDir, 0755, true)) {
            throw new Exception('无法创建目录:' . $uploadDir);
        }
    }
    
    // 生成唯一文件名
    $fileExtension = pathinfo($file['name'], PATHINFO_EXTENSION);
    $uniqueFileName = $uploadFileName . '_' . time() . '_' . uniqid() . '.' . $fileExtension;
    $filePath = $uploadDir . $uniqueFileName;
    
    // 移动上传的文件
    if (!move_uploaded_file($file['tmp_name'], $filePath)) {
        throw new Exception('文件保存失败');
    }
    
    // 如果是图片,生成缩略图
    $thumbnailPath = '';
    if (in_array($file['type'], ['image/jpeg', 'image/jpg', 'image/png', 'image/gif'])) {
        $thumbnailPath = $uploadDir . 's_' . $uniqueFileName;
        createThumbnail($filePath, $thumbnailPath, 100, 0);
    }
    
    // 返回成功信息
    $response = [
        'success' => true,
        'message' => '文件上传成功',
        'data' => [
            'originalName' => $file['name'],
            'fileName' => $uniqueFileName,
            'filePath' => str_replace('../', 'https://sys.966120.com.cn/', $filePath),
            'thumbnailPath' => $thumbnailPath ? str_replace('../', 'https://sys.966120.com.cn/', $thumbnailPath) : '',
            'fileSize' => $file['size'],
            'fileType' => $file['type'],
            'uploadTime' => date('Y-m-d H:i:s')
        ]
    ];
    
    echo json_encode($response);
    
} catch (Exception $e) {
    echo json_encode([
        'success' => false,
        'message' => '上传失败:' . $e->getMessage()
    ]);
}
 
/**
 * 创建缩略图
 * @param string $sourcePath 源图片路径
 * @param string $targetPath 目标缩略图路径
 * @param int $width 宽度
 * @param int $height 高度(0表示按比例缩放)
 */
function createThumbnail($sourcePath, $targetPath, $width, $height) {
    $imageInfo = getimagesize($sourcePath);
    if (!$imageInfo) {
        return false;
    }
    
    $sourceWidth = $imageInfo[0];
    $sourceHeight = $imageInfo[1];
    $imageType = $imageInfo[2];
    
    // 计算缩略图尺寸
    if ($height == 0) {
        $height = floor($width / $sourceWidth * $sourceHeight);
    } elseif ($width == 0) {
        $width = floor($height / $sourceHeight * $sourceWidth);
    }
    
    // 创建源图像
    switch ($imageType) {
        case IMAGETYPE_GIF:
            $sourceImage = imagecreatefromgif($sourcePath);
            break;
        case IMAGETYPE_JPEG:
            $sourceImage = imagecreatefromjpeg($sourcePath);
            break;
        case IMAGETYPE_PNG:
            $sourceImage = imagecreatefrompng($sourcePath);
            break;
        default:
            return false;
    }
    
    if (!$sourceImage) {
        return false;
    }
    
    // 创建缩略图
    $thumbnailImage = imagecreatetruecolor($width, $height);
    
    // 保持PNG透明度
    if ($imageType == IMAGETYPE_PNG) {
        imagealphablending($thumbnailImage, false);
        imagesavealpha($thumbnailImage, true);
        $transparent = imagecolorallocatealpha($thumbnailImage, 255, 255, 255, 127);
        imagefilledrectangle($thumbnailImage, 0, 0, $width, $height, $transparent);
    }
    
    // 调整图像大小
    imagecopyresampled($thumbnailImage, $sourceImage, 0, 0, 0, 0, $width, $height, $sourceWidth, $sourceHeight);
    
    // 保存缩略图
    $result = false;
    switch ($imageType) {
        case IMAGETYPE_GIF:
            $result = imagegif($thumbnailImage, $targetPath);
            break;
        case IMAGETYPE_JPEG:
            $result = imagejpeg($thumbnailImage, $targetPath, 90);
            break;
        case IMAGETYPE_PNG:
            $result = imagepng($thumbnailImage, $targetPath, 9);
            break;
    }
    
    // 释放内存
    imagedestroy($sourceImage);
    imagedestroy($thumbnailImage);
    
    return $result;
}
?>