GetSimple Support Forum

Full Version: Image upload: renaming issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi all,

I'm just running into some problems here with the file upload script.
For a customer project I need to ensure that all images uploaded are also available in Retina high resolution. As per Apple's specifications this can be achieved by having the exact image in two different resolutions:
One with the standard resolution and one high resolutions version of the same, which is named like: picture@2x.jpg
With this basics I have a jQuery script checking for the device resolution. If it's a Retina, it will automatically search for the @2x version of the image in the same folder.
My problem is that the upload script is stripping off the @ while uploading and I am not able to get this solved by myself. I found the functions 'clean_img_name' and 'to7bit' in admin/basic.php which seems to be the right place, but by removing the @ and/or trying some other things, I am not able to get this solved.

As this is just for this specific project and I need to ensure the customer is easily able to upload images by themselves, can anybody help me modifying the script?

Thanks in advance!
clean_img_name removes @ and then urlencodes the string.

MODIFIED
PHP Code:
function clean_img_name($text)  { 
    
$text strip_tags(lowercase($text)); 
    
$code_entities_match =   array(' ?',' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','/','*','+','~','`','='); 
    
$code_entities_replace = array('','-','-','','','@','','','','','','','','','','','','','','','','','','','',''); //EDITED @
    
$text str_replace($code_entities_match$code_entities_replace$text); 
    
// $text = urlencode($text); // REMOVED
    
$text str_replace('--','-',$text);
    
$text rtrim($text"-");
    return 
$text


(Also these is double encoding during the rename -n if existing. so instead of @->%40 we get %2540)

I do not know if removing the urlencode is wise, but it works. It might be wiser to convert the '%2540' back to @ after wards instead with str_replace
Thanks for the reply Shawn!
I thought I need to change to7bit afterwards, this has confused me...Smile

I got it working with this now:
PHP Code:
function clean_img_name($text)  { 
    
$text strip_tags(lowercase($text)); 
    
$code_entities_match = array(' ?',' ','--','&quot;','!','@','#','$','%','^','&','*','(',')','+','{','}','|',':','"','<','>','?','[',']','\\',';',"'",',','/','*','+','~','`','='); 
    
$code_entities_replace = array('','-','-','','','@','','','','','','','','','','','','','','','','','','','',''); 
    
$text str_replace($code_entities_match$code_entities_replace$text); 
    
$text urlencode($text);
    
$text str_replace('--','-',$text);
    
$text str_replace('%40','@',$text);
    
$text rtrim($text"-");
    return 
$text


Replaced %40 back to @ afterwards. Thanks for the little push Smile
yeah that should work
cept when uploading an existing file and not overwriting

Depends on the upload method, uploadify or form. it is kind of inconsistent.

This is a bug i just found, I had a todo note on it, but did not realize it was double encoding at the time.
I will probably fix this in 3.3.2
quick fix implemented for 3.3.2 ( hotfixes branch )
https://github.com/GetSimpleCMS/GetSimpleCMS/issues/771
Great Shawn, thanks! Will check tomorrow