This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload file using multipart/form-data
Closes #30
- Loading branch information
1 parent
23afa55
commit f654c30
Showing
5 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
src/core/Directus/Filesystem/Exception/FailedUploadException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Directus\Filesystem\Exception; | ||
|
||
class FailedUploadException extends FilesystemException | ||
{ | ||
protected $uploadedError = 0; | ||
|
||
public function __construct($errorCode) | ||
{ | ||
$this->uploadedError = $errorCode; | ||
parent::__construct(get_uploaded_file_error($errorCode)); | ||
} | ||
|
||
public function getErrorCode() | ||
{ | ||
return $this->uploadedError; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/core/Directus/Filesystem/Exception/FilesystemException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Directus\Filesystem\Exception; | ||
|
||
use Directus\Exception\Exception; | ||
|
||
class FilesystemException extends Exception | ||
{ | ||
const ERROR_CODE = 300; | ||
|
||
public function __construct($message = '') | ||
{ | ||
parent::__construct($message, static::ERROR_CODE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
if (!function_exists('is_uploaded_file_okay')) { | ||
/** | ||
* Checks whether upload file has not error. | ||
* | ||
* @param $error | ||
* | ||
* @return bool | ||
*/ | ||
function is_uploaded_file_okay($error) | ||
{ | ||
return $error === UPLOAD_ERR_OK; | ||
} | ||
} | ||
|
||
if (!function_exists('get_uploaded_file_error')) { | ||
/** | ||
* Returns the upload file error message | ||
* | ||
* Returns null if there's not error | ||
* | ||
* @param $error | ||
* | ||
* @return string|null | ||
*/ | ||
function get_uploaded_file_error($error) | ||
{ | ||
switch ($error) { | ||
case UPLOAD_ERR_INI_SIZE: | ||
$message = 'The uploaded file exceeds max upload size that was specified on the server.'; | ||
break; | ||
case UPLOAD_ERR_FORM_SIZE: | ||
$message = 'The uploaded file exceeds the max upload size that was specified in the client.'; | ||
break; | ||
case UPLOAD_ERR_PARTIAL: | ||
$message = 'The uploaded file was only partially uploaded.'; | ||
break; | ||
case UPLOAD_ERR_NO_FILE: | ||
$message = 'No file was uploaded.'; | ||
break; | ||
case UPLOAD_ERR_NO_TMP_DIR: | ||
$message = 'Missing temporary upload folder'; | ||
break; | ||
case UPLOAD_ERR_CANT_WRITE: | ||
$message = 'Failed to write file to disk.'; | ||
break; | ||
case UPLOAD_ERR_EXTENSION: | ||
$message = 'A PHP extension stopped the file upload'; | ||
break; | ||
case UPLOAD_ERR_OK: | ||
$message = null; | ||
break; | ||
default: | ||
$message = 'Unknown error uploading a file.'; | ||
} | ||
|
||
return $message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters