I'm building a multi step file upload using symfony2.
The first screen allows users to upload a CSV file.
The second screen allows users to map a database column to a CSV column.
I have two methods in my controller, one for each screen.
file_upload => First screen
match_csv => Second Screen
Inside the file_upload method, I have the following code:
return $this->redirect($this->generateUrl('match_csv',
array(
'accountId' => $accountId,
'projectId' => $projectId,
'file' => base64_encode( $file->getPathname() )
)
), 301);
and in my match_csv
method, I have the following code:
$file = base64_decode($file);
$csvFile = new \SplFileObject( $file );
$csvFile->setFlags(\SplFileObject::READ_CSV);
My problem is:
When I switch views from file_upload
to match_csv
, the server returns an error stating that the file no longer exists.
It is of my understanding that PHP deletes temp files as soon as a script's execution stops. Hence, when I switch views in symfony2 the file_upload method stops and the file is deleted.
My questions is/are:
Is there a better alternative to share an uploaded file across views?
Is it a good idea to write a temporary file myself, and then delete it right after I stopped using it so that Symfony2/PHP do not delete it automatically?