Skip to content

Commit 707b9cf

Browse files
committed
Fix paths from file error
- Remove the temp name if the file has an error. - Standardized the name with the PHP conventions.
1 parent 70edac8 commit 707b9cf

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/Http/MultipartParser.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,6 @@ private function parseFile(string $name, string $filename, ?string $contentType,
222222
private function parseUploadedFile(string $filename, ?string $contentType, string $contents): ?UploadedFile
223223
{
224224
$size = strlen($contents);
225-
$tempFileName = tempnam(sys_get_temp_dir(), 'PHP_UPLOAD_FILE_');
226225

227226
// no file selected (zero size and empty filename)
228227
if ($size === 0 && $filename === '') {
@@ -232,7 +231,7 @@ private function parseUploadedFile(string $filename, ?string $contentType, strin
232231
}
233232

234233
return new UploadedFile(
235-
$tempFileName,
234+
'',
236235
$filename,
237236
$contentType,
238237
UPLOAD_ERR_NO_FILE,
@@ -248,7 +247,7 @@ private function parseUploadedFile(string $filename, ?string $contentType, strin
248247
// file exceeds "upload_max_filesize" ini setting
249248
if ($size > $this->uploadMaxFilesize) {
250249
return new UploadedFile(
251-
$tempFileName,
250+
'',
252251
$filename,
253252
$contentType,
254253
UPLOAD_ERR_INI_SIZE,
@@ -259,14 +258,15 @@ private function parseUploadedFile(string $filename, ?string $contentType, strin
259258
// file exceeds MAX_FILE_SIZE value
260259
if ($this->maxFileSize !== null && $size > $this->maxFileSize) {
261260
return new UploadedFile(
262-
$tempFileName,
261+
'',
263262
$filename,
264263
$contentType,
265264
UPLOAD_ERR_FORM_SIZE,
266265
true,
267266
);
268267
}
269268

269+
$tempFileName = tempnam(sys_get_temp_dir(), 'php');
270270
file_put_contents($tempFileName, $contents);
271271

272272
return new UploadedFile(

0 commit comments

Comments
 (0)