I’m still having an issue with nGen FileField’s ability to rename/ apend a filename if it alreasy exists. It works fine until the 10th iteration, when it starts overwriting the file , _1, _2, _3… _9, _10, _10, _10…. (see my first post on this a few posts up) This creates problems.
Here is the relevant code from ft.ngen_file_field.php. This looks like a RegEx issue. Any suggestions for fixing this?
// Check if file exists already, if it does add an increment to the file name
if( file_exists($upload_path . $file_name) ) {
$matching_files = glob($upload_path . $file['name'] . "*" . $file['ext']);
// Find highest number, add 1 and set new $file_name
sort($matching_files);
preg_match("/" . $file['name'] . "_(\d+)\." . substr($file['ext'], 1) . "/", basename(end($matching_files)), $matches);
if( isset($matches[1]) && $matches[1] ) {
$increment = "_" . ($matches[1] + 1);
} else {
$increment = "_1";
}
$file_name = $file['name'] . $increment . $file['ext'];
//
}
//
Thanks!
Whoa…absolutely awesome extension. I am using the file upload with matrix. I notice that the file upload returns a relative path that has a leading slash. I always use absolute paths for links so that they never break even when I have some segment variables on the end of the url.
Is there a way to control the output to not include the leading slash so I could use: {site_url}{file}
or
Include the site url?
Ooops. One other question. Is there somewhere that documents all the parameters and variables other than: http://www.ngenworks.com/software/ee/ngen-file-field/
I see that there is the parameter show=”filename” added on 0.9.9. Is that the only parameter? Am I missing something or is that all the parameters?
I’ve just started to use the nGen File Field extension. Unfortunately, I have a problem with image thumbnails.
On publishing an entry, the image selected in the File Field is correctly uploaded to the relevant upload directory. The extension also creates the “thumbs” subdirectory. But no thumbnail is generated, so nothing is displayed in the edit form.
As far as I know, I have all the necessary requirements for the extension to work (jQuery for CP and FieldFrame. Permissions on the image directories are set to 777.
Any ideas why the thumbnails aren’t created? Is there another requirement I’ve missed?
Many thanks.
I’m still having an issue with nGen FileField’s ability to rename/ apend a filename if it alreasy exists. It works fine until the 10th iteration, when it starts overwriting the file , _1, _2, _3… _9, _10, _10, _10…. (see my first post on this a few posts up) This creates problems.
MotoNomad,
The RegEx on the nGen File Field looks fine, but their logic is a little off. When the ft.ngen_file_field.php runs it looks for a file name match and then determines the highest numbered file name by sorting an array of matches and grabbing the last item from the list. Everything works fine until you hit double digits at which point the sort method returns an alphabetical list like this:
file.jpg file_1.jpg file_10.jpg file_2.jpg file_3.jpg file_4.jpg file_5.jpg file_6.jpg file_7.jpg file_8.jpg file_9.jpg
What you want is the natural sort order:
file.jpg file_1.jpg file_2.jpg file_3.jpg file_4.jpg file_5.jpg file_6.jpg file_7.jpg file_8.jpg file_9.jpg file_10.jpg
The problem is on line 554 of ft.ngen_file_field.php (I’m looking at v0.9.10). Just replace line 554’s
sort($matching_files);
with
natsort($matching_files);
and your are in business.
It would seem that my problem is the same as this one; that is, the file name for the thumbnail in the control panel is being placed outside of the image’s src attribute:
<a href="http://www.example.com/images/uploads/440x250-01.jpg%22class=%22ngen-file-link" class="ngen-file-link" target="_blank" rel="noopener">_http://www.example.com/images/uploads/_440x250-01.jpg_</a>
And shouldn’t the src be to the thumbs subdirectory?
Is this a known issue? Is there a cure? Have tried removing and reinstalling the extension but to no avail. All help gratefully received.
@dpdexter: I don’t really know what you mean by a ‘sized’ directory.
I have several distinct upload directories, each with 777 permissions. Images are uploaded correctly, and a ‘thumbs’ directory has been created by nGen File Field. But no thumbnail image is created - the ‘thumbs’ directories are empty - and there’s the problem with the src attribute.
Am I missing another extension (aside from FieldFrame and jQuery for CP) that should be installed for File Field to work? Something for image resizing? The native EE image resizing using GD2 works fine.
@FullCremMilkMan - Sorry I meant a ‘sized’ directory in your ‘images’ folder. In your images folder you should have:
/images/sized /images/uploads etc….
The plugin uses the ‘sized’ directory for storing the cached resized images. Can you post your code (just the part where you are calling the plugin) so we can see if there is an issue there?
Thanks, David
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.