arndta / TinyFileManager.NET

A file manager plugin for TinyMCE v4
28 stars 20 forks source link

image file extensions issue #9

Closed mikeworks closed 10 years ago

mikeworks commented 10 years ago

I ran into a problem when images being uploaded had extensions that used capital letters (I know!!, but I cannot control everything my clients might do). I went through the code and lowered the case for the extensions where it made sense, including when checking if something was an image, etc. and when saving the image and thumbnail. Perhaps controlling for this situation could be added to source?

And thanks a TON for this.

arndta commented 10 years ago

I believe I've done this in recent releases, but I'll verify that.

On Thu, Apr 17, 2014 at 4:52 PM, mikeworks notifications@github.com wrote:

I ran into a problem when images being uploaded had extensions that used capital letters (I know!!, but I cannot control everything my clients might do). I went through the code and lowered the case for the extensions where it made sense, including when checking if something was an image, etc. and when saving the image and thumbnail. Perhaps controlling for this situation could be added to source?

And thanks a TON for this.

— Reply to this email directly or view it on GitHubhttps://github.com/arndta/TinyFileManager.NET/issues/9 .

mikeworks commented 10 years ago

I downloaded today the latest version and still had the issue. I greatly appreciate that you were so quick to reply.

Making a little donation right now.

Michael Fouquette

From: Andy Arndt Sent: ‎Thursday‎, ‎April‎ ‎17‎, ‎2014 ‎2‎:‎56‎ ‎PM To: arndta/TinyFileManager.NET Cc: Michael J. Fouquette

I believe I've done this in recent releases, but I'll verify that.

On Thu, Apr 17, 2014 at 4:52 PM, mikeworks notifications@github.com wrote:

I ran into a problem when images being uploaded had extensions that used capital letters (I know!!, but I cannot control everything my clients might do). I went through the code and lowered the case for the extensions where it made sense, including when checking if something was an image, etc. and when saving the image and thumbnail. Perhaps controlling for this situation could be added to source?

And thanks a TON for this.

— Reply to this email directly or view it on GitHubhttps://github.com/arndta/TinyFileManager.NET/issues/9 .

— Reply to this email directly or view it on GitHub.

arndta commented 10 years ago

First, thanks for the donation! Much appreciated!

I found that there is lower-casing in the javascript where extensions are concerned. Are you expecting it to lower-case the extension when saving the uploaded file (which is reasonable)? If that's not it, can you point out where I've missed casing the extension?

Thanks for the feedback.

mikeworks commented 10 years ago

I do usually like to lower-case file names (and also remove spaces, I’m a little controlling like that, lol).

When I loaded up the dialog.aspx file on it’s own (not plugged into the TinyMCE), I could see two things were happening when we had a full-size image with capital letters in the extension:

Although the full-size image was showing, it, was not being identified as an “image” - just a plain file.

Also, when actually uploading the images with the upper-cased extension, the full-size was saved, but the thumbnail was not.

So I went hunting. I saw that the allowed file extensions are all lower case (as they should be), but when comparing them (isImageFile, isVideoFile, etc) you weren’t lowering the case of the file extension you were reading in, thus it failed being identified as an image (or anything else besides a generic file).

And when uploading a file, you rightly make sure that the file is an image. But since the isImageFile wasn’t compensating for the upper-cased extension, it thought it wasn’t an image and would not call to CreateThumbnail().

So here’s what I did:

For each of the isImageFile, isVideoFile,etc Boolean checks, to be sure to always compare apples to apple and not apples to APpLes, I appended .ToLower(), like this:

intPosition = Array.IndexOf(this.objConfig.arrAllowed[…]Extensions, Path.GetExtension(strFilename).ToLower().TrimStart('.'));

Just for fun while I was in there, I re-factored the calls to these Boolean checks and such, like this in loadFile, original lines 339-349:

foreach (string strF in arrFiles){ […] this.objFItem.strPath = this.strCurrPath + Path.GetFileName(strF); (kept this the same to match the actual filename) (added) string FileName = Path.GetFileName(strF).ToLower(); this.objFItem.boolIsImage = this.isImageFile(FileName); this.objFItem.boolIsVideo = this.isVideoFile(FileName); this.objFItem.boolIsMusic = this.isMusicFile(FileName); this.objFItem.boolIsMisc = this.isMiscFile(FileName); }

I know I did not necessarily need to lower the filename here, but I did. Over-compensation I guess.

For the issues I had, all that was left to do was to make sure we lowered the case of the uploaded thumbnail, which, as you can easily surmise was simply a matter of:

objTNImage.Save(strThumbFilename.ToLower());

in CreateThumbnail()

But I did also want to make sure the full-size image filename was also lower-cased, so I did this in the Switch(strCmd) for upload case, original lines 236-240:

if ((filUpload != null) && (filUpload.ContentLength > 0))

{

strTargetFile = (this.objConfig.strUploadPath + this.strFolder + filUpload.FileName).ToLower(); strThumbFile = (this.objConfig.strThumbPath + this.strFolder + filUpload.FileName).ToLower(); (again, I know that CreateThumbnail() will lower the case, but I over-compensated here too. It’s what I do I guess.)

Hope this makes sense. I had been looking for exactly this while developing a little custom MVC CMS I can use for future projects. You’ve saved me some $$ and some serious time. Happy to lend an open-source hand.

Now if I could just find the time to seriously update my own site, lol. It’s been waaaay too long.

Michael

From: Andy Arndt Sent: ‎Thursday‎, ‎April‎ ‎17‎, ‎2014 ‎7‎:‎44‎ ‎PM To: arndta/TinyFileManager.NET Cc: Michael J. Fouquette

First, thanks for the donation! Much appreciated!

I found that there is lower-casing in the javascript where extensions are concerned. Are you expecting it to lower-case the extension when saving the uploaded file (which is reasonable)? If that's not it, can you point out where I've missed casing the extension?

Thanks for the feedback.

— Reply to this email directly or view it on GitHub.

arndta commented 10 years ago

Added your findings and one of your suggestions. Thanks for the help!

mikeworks commented 10 years ago

You did the heavy lifting. Thank you.

Michael

On Apr 18, 2014, at 17:34, Andy Arndt notifications@github.com wrote:

Added your findings and one of your suggestions. Thanks for the help!

— Reply to this email directly or view it on GitHubhttps://github.com/arndta/TinyFileManager.NET/issues/9#issuecomment-40855737 .