Search

I've been having some thoughts about this issue Michael, and have an idea, but I'll discuss that with you when I have some time.

When you're ready to come back to this, give me a shout...

At work we've been using this instead of the standard upload field fairly frequently for more than a year: https://github.com/rowan-lewis/advanced_upload_field

I'm not sure how it compares with the unique upload field, but it does support serializing filenames, and has delegates for adding media previews and storing extra media meta-data.

Perhaps it's time to merge?

Edit

I also forgot to mention that while mine sanitizes the file name, it also stores the original filename so that it can be displayed instead of the serialized filename.

@buzzomaic, I had the idea of storing the original filename, storing the physical file as a hash, and then having a /download script run (like JIT) to make sure the file downloads with the original name.

Sounds similar to yours!

Media meta data is almost a must IMO, @alpacaaa made the Image Information field a while back to help me out with IPTC data, does your field store this data in the DB?

The original Upload field stored it as a serialized PHP array in the database. Mine does the same thing, alternatives can be considered.

@Rowan:

It is my impression that the Unique Upload Field is used a lot out there, because it provides a dead-simple and unbreakable approach to a simple issue: unique filenames. Hey, did I say unbreakable? Probably yes, because this extension contains just a few lines of code. A single feature, and I never attempted to add more. I love the simplicity of this extension.

So in my eyes the Unique Upload Field can never compare to a more complex extension like your Advanced Upload Field. That also means that there is no reason to merge them.

If anybody would like to fork my extension or take the filename logic and use it in a different extension, please go ahead!

Unique Upload Field updated to version 1.4.1 on 2nd of June 2011

This is a very small update (thanks to @ahwayakchih) to the REGEX which is not crucial in normal usage. See disucussion.

Unique Upload Field updated to version 1.4.2 on 19th of August 2011.

Small update which explicitly sets CHARSET and COLLATION when creating the database table. (AFAIK this is now considered good practice in Symphony.)

@michael

Can you please explain why the name is reduced to maximum 50 characters?

## since uniqid() is 13 bytes, the unique filename will be limited to ($crop+1+13) characters;
$crop  = '33';
return preg_replace("/([^\/]*)(\.[^\.]+)$/e", "substr('$1', 0, $crop).'-'.uniqid().'$2'", $filename);

Why can't it be the whole name? (this works, just tested)

return preg_replace("/([^\/]*)(\.[^\.]+)$/e", "'$1-'.uniqid().'$2'", $filename);

You should crop it, somewhere. Otherwise, if the filename hits the max length of your file system (e.g. 255 characters), you will run into problems.

The latest version uses a cropped length of 30 (not 33, as in your example code) because this will result in 48 characters overall (including a 3-character suffix), which is 4 dozens — simply a nice number. :-) I don't see reasons for asset names to be longer than that.

If you like, you may use a much higher value. I wouldn't suggest to remove the cropping though.

which is 4 dozens — simply a nice number.

Good one :) Ok, thanks for the explanation.

Would there be a way to upgrade an exisiting upload field to unique upload field and keep the data? I didn't know about this plugin when I launched the project, and now there are thousands of images in there already. I'm not afraid of SQL, if that helps

thanks!

I've not done it before, but from my understanding of the Symphony database it should be rather easy, because the table structure is the same (both, sym_fields_foo tables and sym_entries_123 tables). Uniqueness is built 'on-the fly' using a unique ID upon saving, but it is never verified. So you should even be able to simply copy your tables without changing the filenames.

(Correct me if I am wrong. It's late, and once again I have missed a deadline for my project, and I am rather tired already...)

Well, it's simple as this changing a field type and inserting a record (use phpMyAdmin):

1_ Identify the field in sym_fields. It's ID is ... 20 (example). Change type from upload to uniqueupload.

Symphony will now know this field is an uniqueupload instead of an upload. You need to move the field settings from upload table to uniqueupload table:

2_ In sym_fields_uniqueupload create a new entry with data from sym_fields_upload record that has field_id = 20

3_ Delete old record from sym_fields_upload.

worked! I also used this method to change from uniquetextfield to regular textfield, and that worked to

muchos gracias, J

worked!

Good :D

I just did the same too. Thanks for the instructions!

You'll do this as well when changing from SBL to SBL+ ;)

Unique Upload Field updated to version 1.5 on 18th of December 2011

Unique Upload Field updated to version 1.7 on 14th of May 2012

https://github.com/michael-e/uniqueuploadfield

  • Tag 1.6 adds a "clean filename" to the output XML (final 2.2.x release)
  • Tag 1.7 adds support for Symphony 2.3

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details