Hi , is it possible to change the file name? How?
+1
I think you can just overwrite the file name field. I just did it like that and it worked:
class FileAttachment extends \Illuminate\Database\Eloquent\Model implements StaplerableInterface { protected $fillable = ['file']; public function __construct(array $attributes = []) { $this->hasAttachedFile('file', [ 'url' => '/data/:class_name/:attachment/:id_partition/:filename', 'path' => ':app_root/storage:url', ]); parent::__construct($attributes); } } class TaskFileAttachmentController extends BaseController { /** * Store a new record. * * @return \Illuminate\Http\Response */ public function store() { $item = new FileAttachment; $item->fill(Input::all()); // Just change the file name :) $item->file_file_name = "new-filename.bin"; $item->save(); } }
I did like this
$file = $request->file('image')->move(public_path('uploads/images'), md5(str_random(25)) . '.jpg'); $article = Article::create([ 'image' => $file, 'body' => $request->post ]);
Now the method instanceWrite is public. We can change the filename using, for example:
$product->image->instanceWrite('file_name', $new_name);
I was thinking if I need to change the filename after the upload, for SEO proposed, is this possible?
For example, I have a field for image description and with this input field, I create the filename for the image.
Activity
algethamy commentedon Sep 17, 2015
+1
NightZpy commentedon Dec 30, 2015
+1
arnekolja commentedon Feb 11, 2016
I think you can just overwrite the file name field. I just did it like that and it worked:
chaot1x commentedon Apr 18, 2016
I did like this
italoborges commentedon Jul 19, 2016
Now the method instanceWrite is public. We can change the filename using, for example:
$product->image->instanceWrite('file_name', $new_name);I was thinking if I need to change the filename after the upload, for SEO proposed, is this possible?
For example, I have a field for image description and with this input field, I create the filename for the image.