22410 Posts in 6905 Topics by 2750 members
|Go to End|
6 March 2010 at 11:34am Last edited: 6 March 2010 11:46am
I'm looking for a method to upload files and images that works across any of the admin screens. None of the built-in solutions are suitable for one reason for another.
For example, the SimpleImageField does not work on the AJAX pop-up forms. I am also having trouble replacing an image once updated, and there does not seem to be a way to remove an image once uploaded. However, it *does* honour the paths and other parameters passed into it, so as a developer I have full control over where images get uploaded.
The iframe version of the ImageField does work on AJAX pop-up forms, since it is essentially independent of that form (it's a form in itself). It does not seem to honour the upload folder settings, so everything gets dumped into assets/Uploads. It also has a browsing feature that I cannot see how to disable - I don't want users to be able to wonder all over the assets area attaching whatever they like.
So - is there something in between? An iframe-based image/file upload field, that allows files to be removed or replaced, but does not allow any kind of server-based browsing (and no back-door into this for users who play around with AJAX), and for which the upload folders are honoured so images are uploaded to a predetermined folder?
PS And I guess to top it all, if two users upload images with the same name, then the second one would get renamed. Images would only be replaced if updated in the context of the original master object they were attached to.
If there are any developers notes on how the iframe upload field works, then they would be immensely helpful. So far as I can tell, the image upload for the iframe happens outside the context of the master DataObject, hence it not picking up the destination upload path. I think ideally the upload should be directed at the current form handler, then the objects can be applied and security checked. AJAX always scares the hell out of me from a security aspect, since so much happens behind the scenes with no way to know just how "open" those update services are.
7 March 2010 at 2:07pm
Have you tried just using a FileField?
7 March 2010 at 2:09pm
Also, in answer to your second question. Silverstripe (in my experience) never deletes files without you telling it too. It usually uploads the new file and renames it: filename_x.jpg (or something similar).
8 March 2010 at 12:08am
I've tried FileField, and its derivatives (SimpleImageField etc.). The problem with FileField is that it does not show you the file that was previously uploaded (that's easily fixed by extending it with a few lines of code).
Also it does not seem to let me upload new file once the parent row has been created. I can create a new item, upload a file at the time it is created, but then it won't let me change it. When the form is submitted, it comes back suspiciously fast (even when I select a 1Mbyte file) so I suspect there is something wrong with the edit form itself, but I can't fathom out what.
As well as fixing that, it needs a "remove" checkbox or icon so the file can be removed from the parent item.
Like I say - there are lots of options for uploading, but none of them seem to tick all the boxes.
8 March 2010 at 1:47am
Ok, I see what you are getting at now. That is a bit of a pain. I don't think there is a built in solution, but you could duplicate one of the IframField Classes and then use it to create your own custom field. Something like MyIframeField.
You could add this class to your mysite directory, and then edit the EditForm() method in that class. As IframeFields also have an associated template as well, you would have to duplicate that template and rename it to match your new field type.
I did a similar thing recently to allow me to make some large modifications to a CheckboxSetField, and it worked really well.
Hope that is what you are looking for,
8 March 2010 at 2:38am
Yes, I think that is what I am going to have to do - understand how the current fields work then write my own. I am thinking of using the jQuery AJAX uploader to do the uploading. It doesn't have a progress bar (you need either Flash on the client or an upload daemon - usually Perl - on the server to do that - Perl allows the uploaded file to be streamed onto the file system while at the same time updating an upload progress file that the client can poll - PHP does not allow that since PHP will not get called until *after* the complete file has been uploaded). Anyway, this is the tool:
One thing my uploader would need to do, that none of the others seem to do (except the simple file uploader), is to accept the submitted file in the context of the Form Item that submitted it. In the case of an Admin screen, it would be the form field defined in the DataObject that would be loaded and used to determine where the file goes and whether the user has permission to upload that file anyway.
There are many other ways forms can be created, so if it's not done directly through a DataObject, I'm not sure where the server-side of the upload mechanism would get its permissions and settings from.
The other thing I would like to do is allow the files to be uploaded *before* the master record is created. All the new-item form needs to know is what the ID of the files(s) that have been uploaded are, and it can link to those files either before or after the master record is written. Again, security would need to ensure that nobody could send arbitrary file IDs to link to any arbitrary uploaded file and take control of it.
|Go to Top|