Nos\Attachment¶Binds a file to an object.
Nos\Attachment::$attached¶Required. The attached ID.
Nos\Attachment::$dir¶Required.
Directory path, where the attachment is stored. Relative to local/data/files.
Nos\Attachment::$alias¶An URL alias to access the directory path.
Nos\Attachment::$extensions¶Array of valid files extensions.
Nos\Attachment::$image¶If true, accepts only files with an image extension. Same that extensions set to array('jpg', 'gif', 'png', 'jpeg').
Nos\Attachment::$check¶Used it to make the attachment private. A callback function to check permissions against. It takes a single parameter: Attachement instance.
Nos\Attachment::forge($attached, $config)¶| Parameters: |
|
||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Returns: | A new |
Nos\Attachment::newFile()¶| Returns: | Get the new attachment file path if one, false if no file exists. |
|---|
Nos\Attachment::path()¶| Returns: | Get the attachment file path or false if no file exists. |
|---|
Nos\Attachment::filename()¶| Returns: | Get the attachment filename or false if no file exists. |
|---|
Nos\Attachment::extension()¶| Returns: | Get the attachment extension or false if no file exists. |
|---|
Nos\Attachment::isImage()¶| Returns: | True if the Attachment is an image, false otherwise. |
|---|
Nos\Attachment::url($absolute = true)¶| Parameters: |
|
|---|---|
| Returns: | Get the attachment url or |
Nos\Attachment::urlResized($max_width = 0, $max_height = 0, $absolute = true)¶| Parameters: |
|
|---|---|
| Returns: | Get the resized url for the Attachment or |
Nos\Attachment::htmlAnchor($attributes = array())¶| Parameters: |
|
|---|---|
| Returns: | Returns an HTML anchor tag with, by default, attachment URL in href and attachment filename in text. |
Nos\Attachment::getToolkitImage()¶| Returns: | Returns a Nos\Toolkit_Image based on the attachment if is an image, False otherwise. |
|---|
Nos\Attachment::set($file, $filename = null)¶| Parameters: |
|
|---|---|
| Returns: | Set a new Attachment file. |
| Throws: | FuelCoreFileAccessException if new file have a not allowed extension. |
Nos\Attachment::save()¶Save a new Attachment file
| Returns: | True if the Attachment have been saved, false otherwise. |
|---|
Nos\Attachment::delete()¶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();