質問編集履歴
2
コードの詳細の追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -32,30 +32,266 @@
|
|
32
32
|
|
33
33
|
Class XXX{
|
34
34
|
|
35
|
+
|
36
|
+
|
37
|
+
public function upload_material_confirm(Request $request)
|
38
|
+
|
39
|
+
{
|
40
|
+
|
41
|
+
$filename = $request->file('filedata')->getClientOriginalName();
|
42
|
+
|
43
|
+
$path = $request->file('filedata')->storeAs('material', $filename);
|
44
|
+
|
45
|
+
$originalFile = $path;
|
46
|
+
|
47
|
+
$data = $request->all();
|
48
|
+
|
35
|
-
|
49
|
+
$user = \Auth::user();
|
36
50
|
|
37
51
|
}
|
38
52
|
|
39
53
|
|
40
54
|
|
55
|
+
private $originalFile ; // 元ファイルのパス情報
|
56
|
+
|
57
|
+
private $pdfFile ; // 変換したPDFファイルのパス情報
|
58
|
+
|
59
|
+
private $isNoExtension = FALSE ; // 拡張子が無い場合
|
60
|
+
|
61
|
+
private $isNoFilename = FALSE ; // ファイル名が無い場合
|
62
|
+
|
63
|
+
private $isPDF = FALSE ; // 元ファイルはPDFか
|
64
|
+
|
65
|
+
private $isConvertible2PDF = FALSE ; // 元ファイルはPDFに変換対象か
|
66
|
+
|
67
|
+
private $beConvertedPDF = FALSE ; // PDFへ変換済みか
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
public function __construct($full_path) {
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
$this->setOriginalFile($full_path) ;
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
// 拡張子を調べてフラグを立てておく
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
if( ! isset($this->originalFile["extension"]) ) {
|
86
|
+
|
87
|
+
// 拡張子が無い場合。("extension"が未定義の場合)
|
88
|
+
|
89
|
+
$isNoExtension = TRUE ;
|
90
|
+
|
91
|
+
$this->originalFile["extension"] = "" ;
|
92
|
+
|
93
|
+
}
|
94
|
+
|
95
|
+
if( ! $this->originalFile["filename"] ) {
|
96
|
+
|
97
|
+
// ファイル名が無い場合。("filename"が空文字列の場合)
|
98
|
+
|
99
|
+
$isNoFilename = TRUE ;
|
100
|
+
|
101
|
+
$this->originalFile["filename"] = "" ;
|
102
|
+
|
103
|
+
}
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
if( in_array( $this->originalFile["extension"], configODF::EXTENSIONS_PDF) ) {
|
108
|
+
|
109
|
+
// 拡張子がPDFのものであれば
|
110
|
+
|
111
|
+
$this->isPDF = TRUE ;
|
112
|
+
|
113
|
+
}
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
if( in_array( $this->originalFile["extension"], configODF::EXTENSIONS_MSOFFICE) ) {
|
118
|
+
|
119
|
+
// 拡張子がMS Officeのものであれば、LibreofficeでPDF変換対象
|
120
|
+
|
121
|
+
$this->isConvertible2PDF = TRUE ;
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
public function setOriginalFile($full_path) {
|
130
|
+
|
131
|
+
if( isset( $this->originalFile ) ) {
|
132
|
+
|
133
|
+
return ;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
$this->originalFile = pathinfo($full_path) ;
|
138
|
+
|
139
|
+
$this->originalFile["fullpath"] = $full_path ;
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
public function setPdfFile($full_path) {
|
146
|
+
|
147
|
+
if( isset( $this->pdfFile ) ) {
|
148
|
+
|
149
|
+
return ;
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
if( ! isset( $full_path ) ) {
|
156
|
+
|
157
|
+
$full_path = configODF::OUTPUT_DIR . "/" . $this->originalFile["filename"] . ".pdf" ;
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
$this->pdfFile = pathinfo($full_path) ;
|
162
|
+
|
163
|
+
$this->pdfFile["fullpath"] = $full_path ;
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
public function getOriginalFile($type) {
|
170
|
+
|
171
|
+
if($type == "all") {
|
172
|
+
|
173
|
+
return $this->originalFile ;
|
174
|
+
|
175
|
+
} else if( $this->originalFile[$type] ) {
|
176
|
+
|
177
|
+
return $this->originalFile[$type] ;
|
178
|
+
|
179
|
+
} else {
|
180
|
+
|
181
|
+
return $this->originalFile ;
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
41
|
-
public function
|
189
|
+
public function getPdfFile($type) {
|
190
|
+
|
191
|
+
if($type == "all") {
|
192
|
+
|
193
|
+
return $this->pdfFile ;
|
194
|
+
|
195
|
+
} else if( $this->pdfFile[$type] ) {
|
196
|
+
|
197
|
+
return $this->pdfFile[$type] ;
|
198
|
+
|
199
|
+
} else {
|
200
|
+
|
201
|
+
return $this->pdfFile ;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
}
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
public function convertOffice2PDF() {
|
210
|
+
|
211
|
+
if( $this->beConvertedPDF ) {
|
212
|
+
|
213
|
+
print "beConvertedPDF is TRUE\n" ;
|
214
|
+
|
215
|
+
return ;
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
$this->beConvertedPDF = TRUE ;
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
if( $this->isConvertible2PDF ) {
|
226
|
+
|
227
|
+
// PDF変換対象であれば、LibreofficeでPDFに変換する
|
228
|
+
|
229
|
+
$this->setPdfFile(NULL) ;
|
230
|
+
|
231
|
+
$oFile = $this->getOriginalFile("all") ;
|
232
|
+
|
233
|
+
$pFile = $this->getPdfFile("all") ;
|
234
|
+
|
235
|
+
$srcfile = escapeshellarg( $oFile["fullpath"] ) ;
|
236
|
+
|
237
|
+
$dstdir = escapeshellarg( configODF::TMP_OUTPUT_DIR ) ;
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
// OfficeをPDFに変換するコマンドを取得。
|
242
|
+
|
243
|
+
$office2pdf_cmd = str_replace( array("[SRCFILE]", "[DSTDIR]"),
|
244
|
+
|
245
|
+
array($srcfile, $dstdir),
|
246
|
+
|
247
|
+
configODF::OFFICE2PDF_CMD) ;
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
if ( exec($office2pdf_cmd, $output, $ret) ) {
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
$tmp_pdf_file_path = configODF::TMP_OUTPUT_DIR . "/" . $oFile["filename"] . ".pdf" ;
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
rename( $tmp_pdf_file_path, $pFile["fullpath"] ) ;
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
return $this->pdfFile ;
|
264
|
+
|
265
|
+
} else {
|
266
|
+
|
267
|
+
}
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
} else if( $this->isPDF ) {
|
272
|
+
|
273
|
+
// 元ファイルがPDFであれば、変換せずに、オリジナルファイルそのものをPDFファイルとして登録する。
|
274
|
+
|
275
|
+
$this->pdfFile = $this->originalFile ;
|
276
|
+
|
277
|
+
return $this->pdfFile ;
|
278
|
+
|
279
|
+
} else { // 拡張子がMS OfficeでもPDFでもない場合は処理しない。
|
280
|
+
|
281
|
+
$this->pdfFile = NULL ;
|
282
|
+
|
283
|
+
return FALSE ;
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
42
292
|
|
43
293
|
}
|
44
294
|
|
45
|
-
|
46
|
-
|
47
|
-
public function XXX{
|
48
|
-
|
49
|
-
}
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
public function upload_material_confirm{
|
54
|
-
|
55
|
-
}
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
295
|
```
|
60
296
|
|
61
297
|
|
1
誤字修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,8 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
+
```
|
32
|
+
|
31
33
|
Class XXX{
|
32
34
|
|
33
35
|
public function XXX{
|
@@ -53,6 +55,8 @@
|
|
53
55
|
}
|
54
56
|
|
55
57
|
}
|
58
|
+
|
59
|
+
```
|
56
60
|
|
57
61
|
|
58
62
|
|