Changing files URL's in mass

Viewing 17 posts - 1 through 17 (of 17 total)
#53432

renzukoken
Participant

Hi everyone,

I have a big issue actually, as i don’t want to modify URLs of each download 1 by 1 after changing my server (new domain name)
I tryied editing the database and replace each http://…. by the new one using notepad++ but when importing the database, all fields in attached files get empty.
Is anyone have an idea how to massively replace a part of the attached files URLs after changing server?

Thank you very much.

#53522

renzukoken
Participant

Any moderator available to answer? i searched the addon list without finding anything usefull

#53567

Shahjada
Keymaster

Sorry, not clear, download URLs are not static, they are dynamically generated and if you move content to another domain , link automatically use the new domain.

#53573

renzukoken
Participant

I mean each time you add a package, for the attached file, I add an URL for the file to download (on an external server, i don’t use the “upload” function), this URL is set by me.

now all my packages have a URL http://ns32……… but i’m moving all my files to a server named http://ns42….. (still an external server, not the one where WordPress is set)
so all my downloads will not work, i can actually go inside each packages 1 by 1 to update the link to the new server, but doing than more than 3000 times is not what i want.

I tryied to modify those packages link directly into the database, but when i do that, when i edit a package, attached file URL is empty.

What are my solutions?

#53655

renzukoken
Participant

Hope there is lol, would be hell annoying to update each package. Still trying to find a solution

#53679

Shahjada
Keymaster

I see, it will require to write some code, you may try using:

global $wpdb;
$data = $wpdb->get_results( "select * from {$wpdb->prefix}postmeta where mey_key='__wpdm_files'" );
foreach($data as $d){
$newurl = array();
$oldurl = maybe_unserialize($d->meta_value);
foreach($oldurl as $id โ–บ $url){
$newurl[$id] = str_replace("ns32", "ns42",$url);
}
update_post_meta($d->post_id, '__wpdm_files', $newurl);
}
#53752

renzukoken
Participant

Thanks, will try that and keep you posted ๐Ÿ™‚

#59853

savvasha
Member

Hello there,

I am in the same situation. Does the proposed code worked for you @Renzukoken ??

Thanks!

#59854

renzukoken
Participant

Hi, I actually managed to un-hack my server so didn’t had to use this script yet (i kept it on a safe place to try as soon as i change server)
But i’ll be very happy to hear about it if someone tries it ^^

#59857

savvasha
Member

I am not hacked but I am in the process to move from a shared hosting to a VPS one. So all of my internal paths of my files should be changed!

I will keep you updated of how will go ๐Ÿ™‚

My first try was to just do an UPDATE through the phpmyadmin, with a total failure. Then I realize that the data ara actually serialized…

#59858

savvasha
Member

It works perfect for 5500+ files!!!

Thanks Shaon!

#59859

renzukoken
Participant

awsome news ๐Ÿ™‚ you just copy past the code into the SQL request of phpmyadmin? or just in a PHP script you run from your webpage

#59868

savvasha
Member

It is a PHP code. Not SQL. I just created a page template with the code inside and run it once!

#59899

renzukoken
Participant

thanks a lot

#64929

renzukoken
Participant

Hi

Sorry to open this old topic, but now changing to a soyoustart server, i decided to follow the steps from this topic to change the files path

From the previous comments look like it woks well, badly, got no clue where to put this code, can anyone guide me for this part?

just tried by copying paste on a template page without result :

Code

Thanks ๐Ÿ˜‰

PS : Can’t it be replaced by an SQL request to do the same thing?

#64942

savvasha
Member

You can not use plain SQL request because the data are serialized!

Just create an empty Page Template, put the code in with the correct modifications for your case. Then create a Test Page using the Page Template you created just before. And run this page ONCE!

You can add some “echo”s just to debug it.

#64959

renzukoken
Participant

Found the issue ๐Ÿ™‚

It was a simple mistake, there is mey_key in the script, a T is missing : meta_key

In the end i created a simple php file at the root of the serveur with inside

include_once('wp-load.php' );
mysql connect etc...

then the script with the missing letter T

And all works perfectly ^^ thanks

Viewing 17 posts - 1 through 17 (of 17 total)

The topic ‘Changing files URL's in mass’ is closed to new replies.