CodeSleeve / stapler

ORM-based file upload package for php.
http://codesleeve.com
Other
538 stars 143 forks source link

Change filename after the Upload #163

Closed italoborges closed 8 years ago

italoborges commented 8 years ago

Is it possible to change de filename after the Upload?

For example, for SEO proposed (image name and alt text), there is an image description field, the image filename is based on the description field val.

The user can upload an image and come back later just to update this field and after this, change the image filename too.

tabennett commented 8 years ago

This is not possible with the current version of Stapler, however I've already implemented this for the 2.0 release that's coming soon (it's on the develop branch). This isn't documented yet, but to use it there you can simply assign an array (instead of just a File field from your form) to your attachment with the new file name and the file itself:

['file' => $request->get('file'), 'file_name' => 'your-new-file-name.jpg']

This allows you to create forms that can both upload and rename a file:

<div class="form-group">
        <label for="file_file_name" class="col-md-1 control-label">Filename</label>

        <div class="col-md-6">
            <input class="form-control" type="text" name="file[file_name]" value="{{ old('file_file_name', $image->file_file_name) }}">
        </div>
    </div>

    <div class="form-group">
        <label for="file.file" class="control-label col-md-1">File</label>

        <div class="col-md-6">
            <input type="file" name="file[file]" class="form-control" id="image">
        </div>
    </div>
italoborges commented 8 years ago

Great, @tabennett Thanks for your answer! I'm going to try this approach.