Skip to content

changing filename #76

Open
Open

Description

Hi ,
is it possible to change the file name? How?

Activity

  1. algethamy commented on Sep 17, 2015

    @algethamy

    +1

  2. NightZpy commented on Dec 30, 2015

    @NightZpy

    +1

  3. arnekolja commented on Feb 11, 2016

    @arnekolja

    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();
        }
    }
    
  4. chaot1x commented on Apr 18, 2016

    @chaot1x

    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
    ]);
    
  5. italoborges commented on Jul 19, 2016

    @italoborges

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions