| 1 |
= sfPropelFileStorage plugin = |
|---|
| 2 |
|
|---|
| 3 |
The `sfPropelFileStoragePlugin` provides functionality for storing files in a database using Symfony. The plugin also caches files as they are retrieved from the database if they are not already cached. |
|---|
| 4 |
|
|---|
| 5 |
== Installation == |
|---|
| 6 |
|
|---|
| 7 |
* Copy the files into the plugin directory |
|---|
| 8 |
|
|---|
| 9 |
* Rebuild your model |
|---|
| 10 |
|
|---|
| 11 |
{{{ |
|---|
| 12 |
symfony propel-build-all |
|---|
| 13 |
}}} |
|---|
| 14 |
|
|---|
| 15 |
* Activate one or more modules in your `settings.yml` |
|---|
| 16 |
* For your backend application: sfPropelFileStorageAdmin (optional) |
|---|
| 17 |
* For your frontend application: sfPropelFileStorage (required for applications that will serve files) |
|---|
| 18 |
|
|---|
| 19 |
{{{ |
|---|
| 20 |
all: |
|---|
| 21 |
.settings: |
|---|
| 22 |
enabled_modules: [default, sfPropelFileStorageAdmin, sfPropelFileStorage] |
|---|
| 23 |
}}} |
|---|
| 24 |
|
|---|
| 25 |
* Clear your cache |
|---|
| 26 |
|
|---|
| 27 |
{{{ |
|---|
| 28 |
symfony cc |
|---|
| 29 |
}}} |
|---|
| 30 |
|
|---|
| 31 |
* Update your routing configuration |
|---|
| 32 |
|
|---|
| 33 |
{{{ |
|---|
| 34 |
# sfPropelFileStorage frontend routing |
|---|
| 35 |
download_by_file_name: |
|---|
| 36 |
url: /download/:name |
|---|
| 37 |
param: { module: sfPropelFileStorage, action: download } |
|---|
| 38 |
|
|---|
| 39 |
download_image_by_file_name: |
|---|
| 40 |
url: /images/:name |
|---|
| 41 |
param: { module: sfPropelFileStorage, action: download } |
|---|
| 42 |
}}} |
|---|
| 43 |
|
|---|
| 44 |
* Update your .htaccess file, commenting out or eliminating the first three lines and adding a new rule to check if the URL points to a real file or not. |
|---|
| 45 |
|
|---|
| 46 |
{{{ |
|---|
| 47 |
# we skip all files with .something |
|---|
| 48 |
# RewriteCond %{REQUEST_URI} \..+$ |
|---|
| 49 |
# RewriteCond %{REQUEST_URI} !\.html$ |
|---|
| 50 |
# RewriteRule .* - [L] |
|---|
| 51 |
RewriteCond %{REQUEST_FILENAME} !-f |
|---|
| 52 |
}}} |
|---|
| 53 |
|
|---|
| 54 |
* optionally override the default file chunk size of 65k in app.yml. |
|---|
| 55 |
|
|---|
| 56 |
{{{ |
|---|
| 57 |
all: |
|---|
| 58 |
file_data_chunk_size: 130370 |
|---|
| 59 |
}}} |
|---|
| 60 |
|
|---|
| 61 |
* For IIS with ISAPIRewrite you'll need to add some rules, such as: |
|---|
| 62 |
|
|---|
| 63 |
{{{ |
|---|
| 64 |
RewriteRule /(images|download)(.*) /index.php/$1$2 [L] |
|---|
| 65 |
}}} |
|---|
| 66 |
|
|---|
| 67 |
* Choose optional user manager system to use with sfPropelFileStorage plugin (defaults to none) |
|---|
| 68 |
|
|---|
| 69 |
* Execute the pake task file-storage-set-user-manager [sfGuard, none] |
|---|
| 70 |
|
|---|
| 71 |
{{{ |
|---|
| 72 |
symfony file-storage-set-user-manager <manager_option> |
|---|
| 73 |
}}} |
|---|
| 74 |
|
|---|
| 75 |
* Rebuild your models |
|---|
| 76 |
|
|---|
| 77 |
{{{ |
|---|
| 78 |
symfony propel-build-model |
|---|
| 79 |
}}} |
|---|
| 80 |
|
|---|
| 81 |
* Clear cache |
|---|
| 82 |
|
|---|
| 83 |
== Server Configuration == |
|---|
| 84 |
This plugin is limited by upload_max_filesize (and potentially post_max_size and max_input_time as well). For post_max_size and max_input_time you'll need to modify your php.ini file explicitly. However, for max_upload_size, you can override the default settings in your app.yml file, e.g.: |
|---|
| 85 |
|
|---|
| 86 |
{{{ |
|---|
| 87 |
all: |
|---|
| 88 |
sf_propel_file_storage_upload_max_filesize: 2M |
|---|
| 89 |
}}} |
|---|
| 90 |
|
|---|
| 91 |
Note that you can use either a number of bytes or the shorthand notation described here: http://www.php.net/manual/en/faq.using.php#faq.using.shorthandbytes |
|---|
| 92 |
|
|---|
| 93 |
There is a validator file provided with the admin module of this plugin that illustrates how to validate filesize. If no validation occurs and the file couldn't be sent, an exception is thrown, so if you're using this in your own module and NOT using validation, you should at least enclose your call to |
|---|
| 94 |
{{{ |
|---|
| 95 |
sfPropelFileStorageUtil::generateFileInfoFromRequest() |
|---|
| 96 |
}}} |
|---|
| 97 |
|
|---|
| 98 |
in a try/catch block. |
|---|
| 99 |
|
|---|
| 100 |
If you do not specify a value for sf_propel_file_storage_upload_max_filesize, the value from php.ini will be used. Please note that sf_propel_file_storage_upload_max_filesize ''only'' applies to saving files with this plugin and no were else. |
|---|
| 101 |
|
|---|
| 102 |
== A Usage Example: Integrating sfPropelFileStorage with Existing Modules == |
|---|
| 103 |
|
|---|
| 104 |
The sfPropelFileStoragePlugin is desingned to easily cooperate with other modules. A basic administration module is provided as part of the plugin. However, use of this module is optional. Follow the steps below to allow other modules in your application to accept files into the sfPropelFileStorage tables. |
|---|
| 105 |
|
|---|
| 106 |
* Add one or more foreign keys in the schema of the object to which you are attaching files. |
|---|
| 107 |
* Modify your templates as appropriate. |
|---|
| 108 |
* In your Update command, generate an sfPropelFileStorageInfo object and attach it to it's parent object. Saving the parent object will save the file_info and file_data in one transaction. |
|---|
| 109 |
|
|---|
| 110 |
{{{ |
|---|
| 111 |
$fileInfo = sfPropelFileStorageUtil::generateFileInfoFromRequest($this->getRequest(), 'uploaded_file'); |
|---|
| 112 |
$object->setsfPropelFileStorageInfo($fileInfo); |
|---|
| 113 |
$object->save(); |
|---|
| 114 |
}}} |
|---|
| 115 |
|
|---|
| 116 |
== Customize sfPropelFileStorage module actions == |
|---|
| 117 |
|
|---|
| 118 |
To customize or add methods to the sfPropelFileStorage actions class: |
|---|
| 119 |
|
|---|
| 120 |
* Create a module in your application named sfPropelFileStorage. |
|---|
| 121 |
|
|---|
| 122 |
* Create an actions.class.php file in that modules Actions directory: |
|---|
| 123 |
|
|---|
| 124 |
{{{ |
|---|
| 125 |
<?php |
|---|
| 126 |
require_once sfConfig::get('sf_plugins_dir').'/sfPropelFileStoragePlugin/modules/sfPropelFileStorage/lib/BasesfPropelFileStorageActions.class.php'; |
|---|
| 127 |
class sfPropelFileStorageActions extends BasesfPropelFileStorageActions |
|---|
| 128 |
{ |
|---|
| 129 |
// add or override methods. |
|---|
| 130 |
} |
|---|
| 131 |
?> |
|---|
| 132 |
}}} |
|---|