Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changing filename #76

Open
ghost opened this issue May 15, 2015 · 5 comments
Open

changing filename #76

ghost opened this issue May 15, 2015 · 5 comments

Comments

@ghost
Copy link

ghost commented May 15, 2015

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

@algethamy
Copy link

+1

1 similar comment
@NightZpy
Copy link

+1

@arnekolja
Copy link

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();
    }
}

@chaot1x
Copy link

chaot1x commented Apr 18, 2016

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
]);

@italoborges
Copy link

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
Projects
None yet
Development

No branches or pull requests

6 participants