I’m using SilverStripe 2.4.7 and I want to add a method that parses the file which I have just uploaded with FileIFrameField. The thing that has me stumped is where to put this. I was thinking of the onAfterWrite method but the file only gets uploaded after the rest of the fields have been saved for the first time so I’m not sure this would work.
My question is: What is the best practice for this kind of thing?
Edit
I have this line of code where $filename is the path to my uploaded file but I keep getting a “no such file or directory error”. I have even tried hardcoding in the filepath but get the same error.
$fh = fopen($filename, 'r');
the best way to parse a new file would be to hook into the uploadfield save method, for the FileIframeField you can do that by sub classing it and overwriting save()
(in SilverStripe 3 there is a new class called UploadField, in UploadField you would need to overwrite
UploadField->upload(SS_HTTPRequest $request), and the file there would be accesable like this:$tmpfile = $request->postVar($this->getName());)below, and example on how to do it in FileIframeField: