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

Keep original file on disk #175

Open
daniel-de-wit opened this issue Nov 10, 2016 · 1 comment
Open

Keep original file on disk #175

daniel-de-wit opened this issue Nov 10, 2016 · 1 comment

Comments

@daniel-de-wit
Copy link

I'm working on a Laravel 5.3 project where the laravel stapler package has been integrated with my model. For testing purposes i've made some database seeds that create some dummy records.

While attaching files to these records, Stapler deletes the original file on disk?
For example:

$filePath = 'some_dir/myfile.png';

$record = MyModel::create([
    'image' => $filePath,
]);

After running, the file located at $filePath is deleted from disk. This is not what I expected, how should I stop Stapler from deleting my files?

@petrmach
Copy link

In case this is still useful to somebody:
When you create the file by path input, Stapler moves the file to the storage. Not sure if that's a feature or a bug, but it does feel inconsistent with e.g. upload from an url.

The workaround would be to just create a temp copy of the file you're uploading.

$filePath = 'some_dir/myfile.png';
$tmpFilePath = sys_get_temp_dir() . "/tmpFile.png";
copy($filePath, $tmpFilePath);

$record = MyModel::create([
    'image' => $tmpFilePath,
]);

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

3 participants