0
我使用Laravel4與Laravel訂書機來操作圖像。如何配置Laravel訂書機的自定義URL
我在網上設計產品目錄,裏面有兩張表。
- 表「產品」具有大約產品,諸如產品名稱,產品尺寸,產品說明和產品高亮圖像的信息。
- 表「Product_Gallery」包含產品的無限制圖像。
而且,我設置模型如下,
class Products extends Eloquent implements StaplerableInterface {
public function __construct(array $attributes = array()) {
$this->hasAttachedFile('product_main_image', [
'styles' => [
'thumb' => ['dimensions' => '100x100#' ],
'display' => ['dimensions' => '300x300#' ],
],
'url' => '/uploads/product/:id/:style/:filename',
]);
...
class ProductGallery extends Eloquent implements StaplerableInterface {
public function __construct(array $attributes = array()) {
$this->hasAttachedFile('product_gallery', [
'styles' => [
'thumb' => ['dimensions' => '100x100#' ],
'gallery' => ['dimensions' => '1024x' ],
],
'url' => '/uploads/gallery/:id/:style/:filename',
]);
...
當我上傳的產品,並有四個庫文件,這些文件存儲如下,
/uploads/product/1/thumb/aaaa.jpg
/uploads/gallery/1/thumb/g1.jpg
/uploads/gallery/2/thumb/g2.jpg
/uploads/gallery/3/thumb/g3.jpg
/uploads/gallery/4/thumb/g4.jpg
我想組產品庫文件上傳到產品文件夾中,例如,
/uploads/product/1/thumb/aaaa.jpg
/uploads/product/1/gallery/1/thumb/g1.jpg
/uploads/product/1/gallery/2/thumb/g2.jpg
/uploads/product/1/gallery/3/thumb/g3.jpg
/uploads/product/1/gallery/4/thumb/g4.jpg
這段代碼在控制器,
$model = new ProductGallery();
$model->fk_id = $product_id;
$model->image = Input::file('file');
$pathInfo = pathinfo(Input::file('file')->getClientOriginalName());
$newFilename = 'gallery-' . date("Ymd-") . sha1(time()) . '.' . $pathInfo['extension'];
$model->image->instanceWrite('file_name', $newFilename);
$model->save();
如何配置的Laravel訂書機?
請提供您的控制器代碼上傳附件。 –
@ArkarAung我已經添加了控制器代碼。 – punny