1
tomodea
EXTGALLERY - Suggested fix for problem with image filenames containing dots
  • 2010/9/8 9:53

  • tomodea

  • Just popping in

  • Posts: 47

  • Since: 2008/2/19


There is a logic error in the class called photoHandler.php when the user tries to upload a photo where the filename of the image contains dots.

Look for this statement in the function called _makeFileName in photoHandler.php in the class folder:
$fileName explode(".",$fileName);


This splits the filename into 2 parts when the first “.” Is encountered:
• $fileName[0]
• $fileName[1]

This is OK when we have a filename such as IMG_8517.JPG - $fileName[0] will be IMG_8517 and $fileName[1] will be JPG.

However, if the user has renamed the file to something like: wedding.bill.and.mary.jpg, then $fileName[0] will be wedding and $fileName[1] will be bill. In other words, the files will be stored with the wrong filetype. This causes problems when a user tries to download the original image because it will be saved with a filetype of bill instead of a filetype of jpg.

To address this problem we need to separate the filename from the filetype. Fortunately there is a simple PHP function to help us do this – pathinfo.

My suggested changes are to add these statements at the start of the _makeFileName function:
$path_parts pathinfo($fileName);
        
$fname $path_parts['filename'];
        
$ftype $path_parts['extension'];


You can then adjust the rest of the code to use $fname and $ftype as appropriate.

Regards, Tom O’Dea
Regards, Tom O'Dea
Melbourne, Australia

2
Peekay
Re: EXTGALLERY - Suggested fix for problem with image filenames containing dots
  • 2010/9/8 11:23

  • Peekay

  • XOOPS is my life!

  • Posts: 2335

  • Since: 2004/11/20


A nice solution, but users will need to check their hosts config to ensure pathinfo is enabled. Some Windows servers do not support this without a plugin.

Also, Xoops Protector will block uploads of multiple-dot files.

Quote:
Attempt to multiple dot file my.new.file.txt


To be honest, although you can use periods in filenames, I imagine those that do have a very frustrating time uploading anything to the internet.
A thread is for life. Not just for Christmas.

3
tomodea
Re: EXTGALLERY - Suggested fix for problem with image filenames containing dots
  • 2010/9/9 9:26

  • tomodea

  • Just popping in

  • Posts: 47

  • Since: 2008/2/19


Quote:

Peekay wrote:
A nice solution, but users will need to check their hosts config to ensure pathinfo is enabled. Some Windows servers do not support this without a plugin.

Also, Xoops Protector will block uploads of multiple-dot files.

Quote:
Attempt to multiple dot file my.new.file.txt


To be honest, although you can use periods in filenames, I imagine those that do have a very frustrating time uploading anything to the internet.


I agree with your point about the use of periods in filenames but this is not a problem in my case. Just to clarify my point where I said "You can then adjust the rest of the code to use $fname and $ftype as appropriate.". I actually scan the $fname and replace certain special characters that might cause problems. These include the single apostrophe (') which I change to (`). I also change any instances of the period to underscore (_).

The filenames used for storing the image files will no longer be the same as entered by the user but this is not an issue because users get to work with photo titles and the filenames should be transparent to them.
Regards, Tom O'Dea
Melbourne, Australia

Login

Who's Online

163 user(s) are online (92 user(s) are browsing Support Forums)


Members: 0


Guests: 163


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Mar 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits