After the showdoc service is migrated, the picture cannot be accessed

When showdoc is migrated, after copying the entire directory to the new directory, the document can be accessed normally. However, the pictures and attachments involved in the md document are no longer accessible.

1. The cause of the problem

The main reason is that the uploaded and returned file addresses are absolute addresses. Viewing the showdoc file path shows that the file path also stores the service domain name. After the service migration, due to the change of the server IP, pictures and files cannot be displayed normally.
insert image description here

2. Solution:

You need to use the SQLiteSpy data tool to operate the local database file of showdocshowdoc.db.php

[Scheme 1] Replace the original service address with the new service address

1. Download the SQLiteSpy data tool

2. Open the showdoc data file with SQLiteSpy, directory: \showdoc\Sqlite\showdoc.db.php

3. Execute batch replacement of SQL statements, change the text and file path to the correct path

The text corresponds to the data table: page, the upload file table: upload_file, and the sql statement example is as follows

--修改正文地址
update page set page_content = replace(page_content,"172.16.101.94","172.16.101.191");
--修改文件地址
update upload_file set real_url= replace(real_url,"172.16.101.94","172.16.101.191");

After the execution is completed, the showdoc pictures and attachments can be displayed normally

[Scheme 2] Replace the original service address with a relative path

1. Process historical data

Change the paths of the text (page) and files and images (upload_file) to relative paths

--修改正文地址
update page set page_content = replace(page_content,"http://172.0.0.1","");
--修改文件地址
update upload_file set real_url= replace(real_url,"http://172.0.0.1","");

insert image description here

2. Modify the code of the upload operation

Find the method \showdoc\server\Application\Home\Controllerin the directory: PageController.class.php file , the code version may be stored in a different directory, but you can find the file uploadImgin the server directory and change it to a relative pathPageController.call.php
get_domain()

{
    
     // 上传成功 获取上传文件信息                
   $url = get_domain() . __ROOT__ . substr($upload->rootPath, 1) . $info['editormd-image-file']['savepath'] . $info['editormd-image-file']['savename'];
   echo json_encode(array("url" => $url, "success" => 1));
}

Guess you like

Origin blog.csdn.net/lqh4188/article/details/130628297