Binds a file to an object.
Required. The attached ID.
Required. Directory path, where the attachment is stored. Relative to local/data/files.
An URL alias to access the directory path.
Array of valid files extensions.
If true, accepts only files with an image extension. Same that extensions set to array('jpg', 'gif', 'png', 'jpeg').
Used it to make the attachment private. A callback function to check permissions against. It takes a single parameter: Attachement instance.
Parameters: |
|
||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns: | A new Nos\Attachment. |
Returns: | Get the new attachment file path if one, false if no file exists. |
---|
Returns: | Get the attachment file path or false if no file exists. |
---|
Returns: | Get the attachment filename or false if no file exists. |
---|
Returns: | Get the attachment extension or false if no file exists. |
---|
Returns: | True if the Attachment is an image, false otherwise. |
---|
Parameters: |
|
---|---|
Returns: | Get the attachment url or false if no file exists. |
Parameters: |
|
---|---|
Returns: | Get the resized url for the Attachment or false if no file exists or it’s not an image. |
Parameters: |
|
---|---|
Returns: | Returns an HTML anchor tag with, by default, attachment URL in href and attachment filename in text. |
Returns: | Returns a Nos\Toolkit_Image based on the attachment if is an image, False otherwise. |
---|
Parameters: |
|
---|---|
Returns: | Set a new Attachment file. |
Throws: | FuelCoreFileAccessException if new file have a not allowed extension. |
Save a new Attachment file
Returns: | True if the Attachment have been saved, false otherwise. |
---|
Delete the Attachment file
Returns: | True if the Attachment have been deleted, false otherwise. |
---|
<?php
$attachment = \Nos\Attachment::forge('my_id', array(
'dir' => 'apps'.DS.'myapps',
'alias' => 'myapps-attachment',
'extensions' => array('pdf'),
'check' => 'check_attachment',
));
// It's for example
$_SESSION['user_connected'] = true;
function check_attachment($attachment) {
return $GLOBALS['user_connected'];
}
try {
$attachment->set('/path/a_doc.doc');
} catch (\Fuel\Core\FileAccessException $e) {
// Exception will be throw, extension is doc, not a pdf.
}
$attachment->set('/path/a_pdf.pdf');
$attachment->save();
// Now file saved in local/data/files/apps/myapps/my_id/a_pdf.pdf
echo $attachment->url();
// Echo http://wwww.domain.ext/data/files/myapps-attachment/my_id/a_pdf.pdf
$_SESSION['user_connected'] = false;
// Now URL http://wwww.domain.ext/data/files/myapps-attachment/my_id/a_pdf.pdf return 404
$attachment->delete();