Hi - I'm currently developing a module that needs to save a file that's been specified in an input tag of file type off a form. I have the form all setup, and normally in PHP at this point I would use move_uploaded_file and specify the $_FILES indexed at 'tmp_name' to grab the temporary file. However, I'm assuming that Gallery 2 intercepts this already and I'm required to use API to get the temporary file, since $_FILES appears to be empty by the time my controller code looks at it. Any ideas how to save an uploaded file? I apologize if this is already posted somewhere and I missed it.
Thanks!
Posts: 4342
The best way to answer queries like this is to deconstruct what Gallery already does in a similar situation - after all, you have the source code. So trace through what happens when you upload an image file, and you'll get the "Gallery" way of doing it.
Posts: 2
I appreciate your response - I actually took a look at the source before I posted this and found a call to a $files variable that appeared to mimic the functionality of $_FILES. However, when I made use of this variable from my module code, it was empty.
Since I ran into a number of dead ends, I was hoping that someone already had an answer to this question. I imagine there are other modules that make use of file uploads, I just don't know of any since I am new to Gallery 2. Thanks again
Posts: 4342
Looking at the way items are added in the ItemAddFromBrowser code:
Firstly main.php does all the work for you by calling
$form = GalleryUtilities::getFormVariables('form');
which makes sure that the contents of $_FILES are returned to you automatically in the $form variable - see this snippet of modules/core/ItemAddFromBrowser.inc (lines 51-60):I guess you could just pretty much copy that approach.