missing file upload after logout & login
- Matúš Matula
- Member | 257
Usecase:
I submit form with file input but meanwhile I got logged out from application
which redirects me to login form. I log in & application tries to restore
latest request ($presenter->restoreRequest($key)), rePOSTing it. File input
contains all data as in original request like
Nette\Http\FileUpload #9f0a
name private => "1 LEKCE - ŠKOLA MYSTERIÍ.doc" (30)
type private => NULL
size private => 221696
tmpName private => "C:\wamp\tmp\phpD1D9.tmp" (23)
error private => 0
but the .tmp file has already been erased by garbage collector in php after original request finished so it cannot be saved now.
Is there a way how to solve it on NetteFW level (resubmit form completely)?
- Matúš Matula
- Member | 257
I don't think it will work → the file does not physically exist after logout & request restoration → GC erased it after original/first request finished
- Jan Tvrdík
- Nette guru | 2595
@MatúšMatula You need to move it before calling
storeRequest
. Then it should work fine.
- Matúš Matula
- Member | 257
@JanTvrdík sry for such a delay, I haven't noticed your reply.. Sure, moving the file before storing the request would certainly solve it but it does not look like system solution (should I check if a file's been submitted everytime user logs out due inactivity & manually restore/move file from temporary storage on every place file uploads are processed? I don't think so..) But resubmitting whole form with files would be.. is it possible somehow?
offtopic: I used to be ‘Nette guru’ once, what's changed since then that I'm a ‘Member’ once again? :) just curious.. I never considered Nette Guru myself anyway
- Jan Tvrdík
- Nette guru | 2595
But resubmitting whole form with files would be.. is it possible somehow?
Yes, you need to move the file =) Otherwise GC will delete it. What's so hard to understand about it?
To make it clear – this is what you need to do:
class BasePresenter extends UI\Presenter
{
public function storeRequest($expiration = '+ 10 minutes')
{
foreach ($this->request->files as $file) {
$file->move($tmpDir . '/' . Nette\Utils\Random::generate());
}
return parent::storeRequest($expiration);
}
}
Last edited by Jan Tvrdík (2015-01-29 22:15)
- Matúš Matula
- Member | 257
@JanTvrdík I get it. I just wonder if it wasn't better solution to
have it built in the framework.. so before storing request nette saves all
submitted files to temp directory & resubmit them on request restore –
automatically – no need for user/programmer to think about this all the time,
on every project.
Or is there a scenario where this is not a good idea?