Websafe Filenaming for Images, should spaces and hyphens be allowed ?

More
2 years 7 months ago - 2 years 7 months ago #80681 by iamrobert
Hi,

I thought FLEXIContent makes image filenames websafe when uploading.

Eg lanterns - copy.jpg to lanterns-002.jpg. Is there a way to enable it?


Here's the issue I'm encountering:  

How do I resolve?
Last edit: 2 years 7 months ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80682 by ggppdk
Hello

These changes are intentional.
Yes we have allowed these in recent versions !

By web-safe you mean using the filenames in URLs
Do you speak of hyphen and space characters ?

Any characters that need to be encode are encoded in the URLs
 


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 2 years 7 months ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago #80684 by iamrobert
Hi ggppdk,

Renaming the files - so that the spaces are removed, hyphens and illegal characters:

www.mtu.edu/umc/services/websites/writing/characters-avoid/

Google file naming recommendation:
developers.google.com/style/filenames

It's done for the URL alias, shouldn't we keep it for the files?


Problems encountered so far:
As a result, trying to obtain the imagesize height and width breaks my code:

    //IMG THUMB WIDTHS/HEIGHTS  
    list( $lsource_w, $lsource_h ) = getimagesize( JURI::base() . $thumbPic[ $i ] );
    $imgDims = 'width="' . $lsource_w . '" height="' . $lsource_h . '" ';

Perhaps there's another way to do this?


Also, Chinese files names come out m_
.jpg:




So - the second image will overwrite the first. 

Is there any way to force websafe files? My clients just want to upload an image and not worry about it breaking their site which this now does.


Cheers,

Robert

 

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80687 by ggppdk
Hello

i have had some others users complain that these 2 characters (space and hyphen) should be allowed
maybe the best is to make this controlled via an option

Which characters are bad ?
[^A-Za-z0-9\(\)\.\_\- ]

To the above we have only added spaces " " and hyphen "-" (the underscore "_" of course was always allowed),


        // Replace with () and multiple space with single, but first remove any leading / trailing spaces
        $file = trim($file);
        $file = str_replace('[', '(', $file);
        $file = str_replace(']', ')', $file);
        $file = preg_replace('![\s]+!', ' ', $file);

        // Replace $*":;|/ with dash after removing any leading / trailing spaces
        $file = preg_replace('![\$\*\"\[\]\:\;\|\/]]+!', '_', $file);

        // Remove any trailing dots, as those aren't ever valid file names
        $file = rtrim($file, '.');

        // Regex for replacing non safe characters
        $regex = array('#(\.){2,}#', '#[^A-Za-z0-9\(\)\.\_\- ]#', '#^\.#');

        // Try to transliterate according to given language and site + admin default languages
        ...

        // Finally if none of transliterations did a good enough job (if less than 50% of file remained)
        // (It could be because of wrong language(s) tried)
        // then avoid bad looking filenames by using current time


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 2 years 7 months ago by ggppdk.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80691 by iamrobert
 Hi ggppdk,

To be more clear hyphens (-) are allowed.

Avoid Spaces in File Names
The space I think is a site killer for us. As spaces in filenames are converted to 
Code:
%20
 it makes it harder to manage a site's assets.Having 
Code:
Image 1.png
 and 
Code:
Image%201.png
 is confusing. It's easier to use i
Code:
mage-001.png
 instead, and is human readable.Then some JS code would need to be rewritten to handle it:
stackoverflow.com/questions/332872/encode-url-in-javascript

Use Hyphens
For SEO,  Google has some more info on URLs and recommends we avoid underscores(_) and use hyphens (-):



Code Examples:
For hugegallery (which we've been phasing out), and our content builder we've just used random names if Chinese is upload. Probably not the best solution but works for us:

Code:
//CONTENT BUILDER /* This is the code to give random name to chinese file name */ if (preg_match('/[\x{4e00}-\x{9fa5}]+.*/u', $imgname) === 1) {   $imgname = rand(0,100000000); } /* Making websafe */ $imgname = preg_replace( '/[^a-z0-9]+/', '-', strtolower( $imgname ) ); /* End */ //HUGE GALLERY         /* Bws This is the code to give random name to chines file name */         if (preg_match('/[\x{4e00}-\x{9fa5}]+.*/u', $file['name']) === 1) {                $file['name'] = rand(0,100000000).".".JFile::getExt($file['name']);         }         /* End */         $file['name'] = JFile::makeSafe($file['name']); // $filenameTemp =  strtolower(flexicontent_upload::sanitize($path, $fileinfo['basename'])); /* Bws This is the code to give random name to chines file name */         if (preg_match('/[^\x00-\x7F]+/', $filenameTemp) === 1 || preg_match('/[\'\/~`\!@#\$%\^&\*\(\)\-\+=\{\}\[\]\|;:"\<\>,\?\\\]/', $filenameTemp) === 1) {               $filenameTemp = rand(0,100000000).".".JFile::getExt($filenameTemp);         }


I know you spent some time here:
github.com/joomla/joomla-cms/issues/7841

It's a tricky issue I know.
 
Last edit: 2 years 7 months ago by iamrobert.

Please Log in or Create an account to join the conversation.

More
2 years 7 months ago - 2 years 7 months ago #80695 by ggppdk
Hello

then ok lets follow google's recommendation
I have committed the change to both 3.3.n and master (FC v4) branches

github.com/FLEXIcontent/flexicontent-cck...faa2fb21d20667a8b3fb

See above to edit your PHP file now and applies the changes


-- Flexicontent is Free but involves a big effort on our part.
Like the our support? (for a bug-free FC, despite having a long list of functions) Like the features? Like the ongoing development and future commitment to FLEXIcontent?
-- Add your voice to the FLEXIcontent JED listing with a 5-star...
Last edit: 2 years 7 months ago by ggppdk.

Please Log in or Create an account to join the conversation.

Moderators: vistamediajoomlacornerggppdk
Time to create page: 0.287 seconds
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline