include/upload_file.php
\UploadFile
- Api
- Manage uploaded files
Properties

array
$filesError= 'array(
UPLOAD_ERR_OK => 'UPLOAD_ERR_OK - There is no error, the file uploaded with success.',
UPLOAD_ERR_INI_SIZE => 'UPLOAD_ERR_INI_SIZE - The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE => 'UPLOAD_ERR_FORM_SIZE - The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL => 'UPLOAD_ERR_PARTIAL - The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'UPLOAD_ERR_NO_FILE - No file was uploaded.',
5 => 'UNKNOWN ERROR',
UPLOAD_ERR_NO_TMP_DIR => 'UPLOAD_ERR_NO_TMP_DIR - Missing a temporary folder.',
UPLOAD_ERR_CANT_WRITE => 'UPLOAD_ERR_CANT_WRITE - Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'UPLOAD_ERR_EXTENSION - A PHP extension stopped the file upload.',
)'
Upload errors
array(
UPLOAD_ERR_OK => 'UPLOAD_ERR_OK - There is no error, the file uploaded with success.',
UPLOAD_ERR_INI_SIZE => 'UPLOAD_ERR_INI_SIZE - The uploaded file exceeds the upload_max_filesize directive in php.ini.',
UPLOAD_ERR_FORM_SIZE => 'UPLOAD_ERR_FORM_SIZE - The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.',
UPLOAD_ERR_PARTIAL => 'UPLOAD_ERR_PARTIAL - The uploaded file was only partially uploaded.',
UPLOAD_ERR_NO_FILE => 'UPLOAD_ERR_NO_FILE - No file was uploaded.',
5 => 'UNKNOWN ERROR',
UPLOAD_ERR_NO_TMP_DIR => 'UPLOAD_ERR_NO_TMP_DIR - Missing a temporary folder.',
UPLOAD_ERR_CANT_WRITE => 'UPLOAD_ERR_CANT_WRITE - Failed to write file to disk.',
UPLOAD_ERR_EXTENSION => 'UPLOAD_ERR_EXTENSION - A PHP extension stopped the file upload.',
)Details- Type
- array
Methods

UploadFile(
string $field_name
=
''
)
:
voidCreate upload file handler
| Name | Type | Description |
|---|---|---|
| $field_name | string | Form field name |

confirm_upload(
)
:
boolstandard PHP file-upload security measures. all variables accessed in a global context
| Type | Description |
|---|---|
| bool | True on success |

create_stored_filename(
)
:
stringcreates a file's name for preparation for saving
| Type | Description |
|---|---|
| string |

duplicate_file(
string $old_id, string $new_id, string $file_name
)
:
voidduplicates an already uploaded file in the filesystem.
| Name | Type | Description |
|---|---|---|
| $old_id | string | old_id ID of original note |
| $new_id | string | new_id ID of new (copied) note |
| $file_name | string | filename Filename of file (deprecated) |

final_move(
string $bean_id
)
:
boolmoves uploaded temp file to permanent save location
| Name | Type | Description |
|---|---|---|
| $bean_id | string | bean_id ID of parent bean |
| Type | Description |
|---|---|
| bool | True on success |

getMime(
array $_FILES_element
)
:
stringGet MIME type for uploaded file
| Name | Type | Description |
|---|---|---|
| $_FILES_element | array | $_FILES element required |
| Type | Description |
|---|---|
| string | MIME type |

getMimeSoap(
string $filename
)
:
stringGuess MIME type for file
| Name | Type | Description |
|---|---|---|
| $filename | string |
| Type | Description |
|---|---|
| string | MIME type |

get_file_path(
string $stored_file_name, string $bean_id, $skip_rename
=
false
)
:
stringbuilds a URL path for an anchor tag
| Name | Type | Description |
|---|---|---|
| $stored_file_name | string | stored_file_name File name in filesystem |
| $bean_id | string | bean_id note bean ID |
| $skip_rename |
| Type | Description |
|---|---|
| string | path with file name |

get_upload_error(
)
:
stringGet upload error from system
| Type | Description |
|---|---|
| string | upload error |

get_upload_path(
string $bean_id
)
:
stringreturns the path with file name to save an uploaded file
| Name | Type | Description |
|---|---|---|
| $bean_id | string | bean_id ID of the parent bean |
| Type | Description |
|---|---|
| string |

get_upload_url(
\SugarBean $document, string $type
=
null
)
:
voidGet URL of the uploaded file related to the document
| Name | Type | Description |
|---|---|---|
| $document | \SugarBean | |
| $type | string | Type of the document, if different from $document |

get_url(
string $stored_file_name, string $bean_id
)
:
stringGet URL for a document
| Name | Type | Description |
|---|---|---|
| $stored_file_name | string | stored_file_name File name in filesystem |
| $bean_id | string | bean_id note bean ID |
| Type | Description |
|---|---|
| string | path with file name |
- Deprecated

realpath(
string $path
)
:
voidReturn real FS path of the file
| Name | Type | Description |
|---|---|---|
| $path | string |

relativeName(
string $path
)
:
voidReturn path of uploaded file relative to uploads dir
| Name | Type | Description |
|---|---|---|
| $path | string |

set_for_soap(
string $filename, string $file
)
:
voidSetup for SOAP upload
| Name | Type | Description |
|---|---|---|
| $filename | string | Name for the file |
| $file | string |

tryRename(
string $filename, string $bean_id
)
:
voidTry renaming a file to bean_id name
| Name | Type | Description |
|---|---|---|
| $filename | string | |
| $bean_id | string |

unlink_file(
string $bean_id, string $file_name
=
''
)
:
voiddeletes a file
| Name | Type | Description |
|---|---|---|
| $bean_id | string | bean_id ID of the parent bean |
| $file_name | string | file_name File's name |

upload_doc(
\SugarBean $bean, string $bean_id, string $doc_type, string $file_name, string $mime_type
)
:
voidUpload document to external service
| Name | Type | Description |
|---|---|---|
| $bean | \SugarBean | Related bean |
| $bean_id | string | |
| $doc_type | string | |
| $file_name | string | |
| $mime_type | string |