Move WFV

Written by r2d2. Posted in PHP, Tips, Wordpress

Transfer WP file version to an other site?

You will need to recalculate the data location length.

Here is a quick made converter.

<?php

/*
Hvis WFV (WP file version) SQL-data skal flyttes til anden webside, kræves det en genberegning af direktorie+fil længe. 

a:4:{s:4:"size";s:6:"2.05Mb";s:4:"path";s:75:"/var/www/htdocs/public_html/noah.crysberg.dk/wp-content/wfv_files/Certifikater.pdf";s:4:"name";s:16:"Certifikater.pdf";s:4:"type";s:3:"pdf";}
                                          ~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Input: filename.sql
Output: NEW-filname.sql
*/

$filename="wp_wfv_files.sql";

$reg='|.*path\\\";s:([0-9]{1,3}):(\\\".*?\\\")|i';

if ($file = fopen($filename, "r")) {
	while(!feof($file)) $a[] = fgets($file);
	fclose($file);
}



$file = fopen("NEW-".$filename, "w");
foreach ($a as $key => $line) { 
	$line = preg_replace_callback(
		$reg,
		function ($matches) {
			return str_replace( 'path\\";s:'.$matches[1], 'path";s:'.(strlen($matches[2])-4), $matches[0]);
		},
		$line
	);
	fwrite($file, $line);
//	echo $line;    	
}
fclose($file);
		
?>

 

75 views