Attachments

Helpdesk for my helpdesk software

Moderator: mkoch227

Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Attachments

Post by Noke101 »

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?
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

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":

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 Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

Many thanks! Its works!
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

Hi! I have some problems with the name of the attachments, please tell me how to fix it?

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()
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. :cry:
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

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?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

Klemen 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?
Attached via form
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

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 Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

Klemen 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.
Done :?
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

There were no files attached to your email.

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 Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

I send it
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

It imported just fine in my test setup?
Image

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 Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

Klemen wrote: Mon Sep 19, 2022 2:09 pm It imported just fine in my test setup?
Image

I have just this part commented out:

Code: Select all

$filename = preg_replace('/[^A-Za-z0-9\.\-_]/','', $filename);
С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 pop3
Klemen
Site Admin
Posts: 10142
Joined: Fri Feb 11, 2005 4:04 pm

Re: Attachments

Post by Klemen »

Same thing, works normally if I attach the two files in the form.

Not sure what is going on on your side :?
Klemen, creator of HESK and PHPJunkyardWas this helpful? You can buy me a drink here Image

Image 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
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

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 :?
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. :cry:
Noke101
Posts: 41
Joined: Mon Aug 09, 2021 11:21 am

Re: Attachments

Post by Noke101 »

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 :?
For the sake of interest, I decided to install a clean HESK copy of the latest version and send a ticket with attachments.
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
Post Reply