News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

phpbb2 converter

Started by stevome, January 20, 2005, 09:16:23 AM

Previous topic - Next topic

stevome

I've just converted my phpbb2 forum to smf and everything went well except -
Our members post a lot of jpgs as attachments.
If the original file had a space or an ampersand in the file name, phpbb2 converted the space and/or ampersand into an underscore,  then wrote the file to disk.
for example -
pic 1.jpg becomes pic_1.jpg
pic&1.jpg becomes pic_1.jpg

The converter looks for the original file name, eg pic&1.jpg, does not find it and therefore does not copy and rename the file.
So you end up with a broken link.

The solution is to convert spaces and ampersands, in the file name,  to underscores.
Would this be possible to implement ? Then my conversion would be 100% successful  :)
Steve.

Oldiesmann

Yep. Easy to do.

phpbb2_to_smf.php

Find
// Frankly I don't care whether they want encrypted filenames - they having it - too dangerous.
$newfilename = $nextID . '_' . str_replace('.', '_', $row['filename']) . md5($row['filename']);


Replace
// Frankly I don't care whether they want encrypted filenames - they having it - too dangerous.
$newfilename = $nextID . '_' . str_replace(array('.','&',' '), array('_','_','_'), $row['filename']) . md5($row['filename']);
Michael Eshom
Christian Metal Fans

stevome

Oldiesmann your code works, but it has not solved the problem :(

For attachments, PHPBB has 2 names
1 the display name
2 the file name on disk

if the attached file is called AA BB&CC.jpg
the display name is AA BB&CC.jpg, but the file name on disk is aa_bb_cc.jpg

if the attached file is called abcd.jpg
the display name and file name on disk are both abcd.jpg

The converter works perfectly if the display name and file name on disk are the same
but fails if they differ

Can anybody fix this ?
Steve.

[Unknown]

#3
Sorry, meant to post this sooner.

-[Unknown]

stevome

i've downloaded the new converter, but no joy, it's still failed to convert arround 20% of the attachments. I downloaded and ran the conversion 3 times just in case :)

Here are 3 examples -
original name : Cannes festival 1977_jpg.jpg
phpbb2 name on disk : cannes_festival_1977_jpg.jpg
smf name on disk : 673_Cannes festival 1977_jpg_jpg907e68c109a535c2fbef1836177f5d6d

original name : db&lennon2.jpg
phpbb2 name on disk : db_lennon2.jpg
smf name on disk : 677_db&lennon2_jpg1c88fce2bb6d835c61b70f73ec261c44

original name : db&lennon.jpg
phpbb2 name on disk : db_lennon.jpg
smf name on disk : http: 678_db&lennon_jpg04e503a89a610bbab174fad269830a49

In each case, in the forum, the picture does not show, but there is a link that when clicked gives -
'404 - Attachment Not Found'

Sorry about this, I don't understand how the attachments work so I cannot pin down what's going wrong.

Steve.

[Unknown]

Testing 1-2-3.

So, it's not the fact that they have &s in them, is it?

Are you saying that "673_Cannes festival 1977_jpg_jpg907e68c109a535c2fbef1836177f5d6d" does indeed EXIST, it just cannot be accessed?  If you get the file from the attachments directory, does it work?

-[Unknown]

stevome

Quote from: [Unknown] on January 23, 2005, 02:21:18 PM
Testing 1-2-3.

So, it's not the fact that they have &s in them, is it?
Arround 20% of the attachments have failed to convert. I've looked at 10 of the failures and all 10 have & or space or capital letters or a combination of all 3.
Quote from: [Unknown] on January 23, 2005, 02:21:18 PM
Are you saying that "673_Cannes festival 1977_jpg_jpg907e68c109a535c2fbef1836177f5d6d" does indeed EXIST, it just cannot be accessed? 
Yes :)
Quote from: [Unknown] on January 23, 2005, 02:21:18 PM
If you get the file from the attachments directory, does it work?

-[Unknown]
I've downloaded 673_Cannes festival 1977_jpg_jpg907e68c109a535c2fbef1836177f5d6d and when I add the .jpg extension , it displays just fine on my windows pc :)

Steve

stevome

Well i got the attachments converter to work :)
my changes are in bold (I used a more meaningfull variable name)
here's the code -

// *** Might want to change the table/where. **********************************
      $result = mysql_query("
         SELECT hxxp:a.post [nonactive]_id AS ID_MSG, ad.real_filename AS filename, ad.physical_filename AS phpbbfilename,
         hxxp:ad.download [nonactive]_count AS downloads, ad.filesize AS size
         FROM {$from_prefix}attachments AS a, {$from_prefix}attachments_desc AS ad
         WHERE hxxp:a.post [nonactive]_id != 0
            AND ad.attach_id = a.attach_id
         LIMIT $_REQUEST[start], 100");
// ****************************************************************************
      // While this is most likely NOT the quickest way it is the easiest to debug/tell what is happening.
      while ($row = mysql_fetch_assoc($result))
      {
         if (!file_exists($oldAttachmentDir . '/' . $row['phpbbfilename']))
            $row['phpbbfilename'] = strtr($row['phpbbfilename'], '& ', '__');

         // Get the true filesize in case the old db lied!
         $fileSize = filesize($oldAttachmentDir . '/' . $row['phpbbfilename']);
         if (!is_integer($fileSize))
            continue;

         // Frankly I don't care whether they want encrypted filenames - they having it - too dangerous.
         $newfilename = $nextID . '_' . strtr($row['phpbbfilename'], '.', '_') . md5($row['phpbbfilename']);

         if (copy($oldAttachmentDir . '/' . $row['phpbbfilename'], $attachmentDir . '/' . $newfilename))
         {
            $setString .= "
               ($nextID, $fileSize, $row[downloads], '" . addslashes($row['phpbbfilename']) . "', $row[ID_MSG]),";

            $nextID++;
         }
      }

      if ($setString != '')
         mysql_query("
            INSERT INTO {$to_prefix}attachments
               (ID_ATTACH, size, downloads, filename, ID_MSG)
            VALUES" . substr($setString, 0, -1));

      $_REQUEST['start'] += 100;
      if (mysql_num_rows($result) < 100)
         break;

      mysql_free_result($result);
   }

:D

Advertisement: