Jump to content

Non-latin characters in attachment files turn to gibberish


Recommended Posts

Posted

I have an IPB 3.4.6 which I am upgrading to IPS 4.1.11 on a Windows machine. The forums are in Hebrew, and some of the attachments have original filenames in Hebrew. 

During the upgrade process some of the attachment files are renamed so that they contain the original filename (as written in the DB). Only trouble is, the Hebrew characters in the filename are turned into gibberish. (Example file can be seen in the photos below). The issue might be that this case was not tested in a Windows environment.

Has anyone else run into this issue? Has anyone managed to solve this problem on his/her own? 

Does anyone have experience with this code and can save me some time and tell me where in the code this file rename occurs? 

Thanks,

Ofra

IPB 3.4.6 attachment DB record.png

IPS 4.1.10 attachment DB record.png

TreeComp comparison.png

Windows Explorer folder.png

Posted

In case anyone else runs into this problem, I'm attaching the code I ran in order to fix the file names.

Use at your own discretion. I take no responsibility for the results/repercussions of using the following code. Read the code before you run it.

I ran this script on my Windows machine. Note: Uploading the files to the Linux server via zip file over FTP, and then unzipping using SSH, the file names got corrupted and unusable. Uploading the files individually over FTP was OK. 

The script assumes that you have run the upgrade already, and after it is done you have MADE A BACKUP of your uploads directory, and have a copy of it in C:\Apache2\htdocs\renamefiles, named "result".

I have put this code in the file C:\Apache2\htdocs\renamefiles\rename.php, then loaded http://localhost/renamefiles/rename.php in my browser.

If you have the same problem, only not with Hebrew but some other language, replace "Windows-1255" with the relevant code-page name. 

You should look at the output in your browser, and look for "FILE NOT FOUND AT ALL" messages -> this would indicate a problem that needs your attention. 

<?php

$resultdir = "C:/apache2/htdocs/renamefiles/result/"; // Change this

$link = mysqli_connect('localhost', $userName, $password, $databaseName); // Change this
if (!$link) {
    die('Could not connect: ' . mysqli_connect_error());
}

$link->set_charset("utf8");
echo 'Connected successfully<br/>';

$result = $link->query("Select * from core_attachments");

if ($result)
{
	while ($row = $result->fetch_assoc())
	{
		$fileid = $row["attach_id"];
		$fileloc = $row["attach_location"];
		echo $fileid . " looking for file: " . $fileloc;
		$postconv = iconv("UTF-8", "Windows-1255", $fileloc);
		$fullpath = $resultdir . $postconv;
		
		if (file_exists($fullpath))
		{
			echo "... file exists. Moving on...<br/>";
		}
		else if (file_exists($resultdir . $fileloc))
		{
			echo "... file exists with gibberish name. Renaming...<br/>";
			rename($resultdir . $fileloc, $fullpath);
		}
		else 
		{
			echo "... FILE NOT FOUND AT ALL! <br/><br/><br/>";
		}	
	}
	
	$result->close();
}

mysqli_close($link);
echo "Done.";
?>

 

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...