Attachments
Moderator: mkoch227
Attachments
Script URL:
Version of script: 3.3.1
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:
Write your message below:
Hello! I have a question regarding the file attachment script.
If the file has a name in Russian, then this script automatically renames it, and if the name is in English, then it does not rename it.
Can I somehow change the work of the script so that it recognizes the Cyrillic alphabet and saves the original file name?
Version of script: 3.3.1
Hosting company:
URL of phpinfo.php:
URL of session_test.php:
What terms did you try when SEARCHING for a solution:
Write your message below:
Hello! I have a question regarding the file attachment script.
If the file has a name in Russian, then this script automatically renames it, and if the name is in English, then it does not rename it.
Can I somehow change the work of the script so that it recognizes the Cyrillic alphabet and saves the original file name?
Re: Attachments
Hesk indeed removes anything except a-z, A-Z, 0-9, ._- from the file name.
This is both for security reasons (to clean up any attempts to pass invalid file names to Hesk) and to prevent encoding-related issues (for example, if file name is in different encoding than utf-8, for example from emails).
If you want to change that, you will need to delete or comment this line in "inc/posting_functions.inc.php":
This is both for security reasons (to clean up any attempts to pass invalid file names to Hesk) and to prevent encoding-related issues (for example, if file name is in different encoding than utf-8, for example from emails).
If you want to change that, you will need to delete or comment this line in "inc/posting_functions.inc.php":
Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
Hi! I have some problems with the name of the attachments, please tell me how to fix it?
This is my code.
I have attached two images of what the files are named and how they are renamed to HESK.
https://ibb.co/VNnk4SJ - names
https://ibb.co/6mkcSNx - names in HESK
I tried to figure out what RegEx is and what it is eaten with, but unfortunately I choked after an hour.
Code: Select all
function hesk_cleanFileName($filename)
{
$parts = pathinfo($filename);
if ( ! isset($parts['extension']))
{
global $hesklang;
die($hesklang['nofex']);
}
$parts['extension'] = preg_replace('/[^A-Za-z0-9\-_]/', '', $parts['extension']);
if ( isset($parts['filename']) )
{
$filename = $parts['filename'];
}
// PHP < 5.2 needs special care
elseif ( version_compare(PHP_VERSION, '5.2','<') )
{
$filename = rtrim( str_ireplace($parts['extension'], '', $filename), '.');
}
else
{
$filename = '';
}
$filename = str_replace( array( '%20', '+' ), '-', $filename );
// $filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = remove_accents($filename);
// $filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
$filename = trim($filename, '-_');
if ( strlen($filename) < 1 || strpos($filename, '.') === 0 )
{
$filename = mt_rand(10000,99999) . $filename;
}
return $filename . '.' . $parts['extension'];
} // END hesk_cleanFileName()
I have attached two images of what the files are named and how they are renamed to HESK.
https://ibb.co/VNnk4SJ - names
https://ibb.co/6mkcSNx - names in HESK
I tried to figure out what RegEx is and what it is eaten with, but unfortunately I choked after an hour.

Re: Attachments
Not sure what's causing that for you; have you tried to also comment out ?
Are the files attached via form or via email?
Code: Select all
$filename = remove_accents($filename);
Are the files attached via form or via email?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
Attached via formKlemen wrote: Fri Sep 16, 2022 5:05 pm Not sure what's causing that for you; have you tried to also comment out?Code: Select all
$filename = remove_accents($filename);
Are the files attached via form or via email?
Re: Attachments
Can you email the two files to pop3test AT hesk DOT com and I will test it locally.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
DoneKlemen wrote: Sun Sep 18, 2022 8:10 am Can you email the two files to pop3test AT hesk DOT com and I will test it locally.

Re: Attachments
There were no files attached to your email.
If your files contain confidential information simply attach a test file with the same name.
If your files contain confidential information simply attach a test file with the same name.
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
It imported just fine in my test setup?

I have just this part commented out:

I have just this part commented out:
Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
Сan you try to insert files when you create a ticket via the form? cuz my clients only use the form, they don't use pop3Klemen wrote: Mon Sep 19, 2022 2:09 pm It imported just fine in my test setup?
I have just this part commented out:Code: Select all
$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
Re: Attachments
Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side
Not sure what is going on on your side

Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here 
You should follow me on Twitter here
Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools


Help desk software | Cloud help desk | Guestbook | Link manager | Click counter | more PHP Scripts ...
Also browse for php hosting companies, read php books, find php resources and use webmaster tools
Re: Attachments
This is very strange, I even deleted just this line from code, HESK still removes the first word in the title, and if the title consists of one word, it simply assigns a random name from numbers.Klemen wrote: Mon Sep 19, 2022 3:56 pm Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side![]()

Re: Attachments
For the sake of interest, I decided to install a clean HESK copy of the latest version and send a ticket with attachments.Klemen wrote: Mon Sep 19, 2022 3:56 pm Same thing, works normally if I attach the two files in the form.
Not sure what is going on on your side![]()
I got the same issue.
Code: Select all
function hesk_cleanFileName($filename)
{
$parts = pathinfo($filename);
if ( ! isset($parts['extension']))
{
$parts['extension'] = 'unknown-file-type';
}
$parts['extension'] = preg_replace('/[^A-Za-z0-9\-_]/', '', $parts['extension']);
if ( isset($parts['filename']) )
{
$filename = $parts['filename'];
}
// PHP < 5.2 needs special care
elseif ( version_compare(PHP_VERSION, '5.2','<') )
{
$filename = rtrim( str_ireplace($parts['extension'], '', $filename), '.');
}
else
{
$filename = '';
}
$filename = str_replace( array( '%20', '+' ), '-', $filename );
$filename = preg_replace('/[\s-]+/', '-', $filename);
$filename = remove_accents($filename);
// $filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
$filename = trim($filename, '-_');
if ( strlen($filename) < 1 || strpos($filename, '.') === 0 )
{
$filename = mt_rand(10000,99999) . $filename;
}
return $filename . '.' . $parts['extension'];
} // END hesk_cleanFileName()
https://ibb.co/5KdGfcH
https://ibb.co/cLcPKzJ