使SAE上的WordPress支持上传图片和附件

运行在SAE上的原版wordpress不支持图片和文件上传,需要修改代码。
1.在应用根目录下,创建sae.php文件:

2.修改wp-includes/functions.php文件:

require( ABSPATH . WPINC . '/option.php' );

前添加如下代码:

include( ABSPATH . '/sae.php' );  //调用SAE的Storage文件域名设置  //for SAE

注释掉如下代码:

//$wrapper = null;
// strip the protocol
//if( wp_is_stream( $target ) ) {
//    list( $wrapper, $target ) = explode( '://', $target, 2 );
//}
// from php.net/mkdir user contributed notes
//$target = str_replace( '//', '/', $target );
// put the wrapper back on the target
//if( $wrapper !== null ) {
//    $target = $wrapper . '://' . $target;
//}

替换为:

//for SAE begin
// from php.net/mkdir user contributed notes
if ( substr($target, 0, 10) == 'saestor://' ) {
return true;
}
$target = str_replace( '//', '/', $target );
//for SAE end

$basedir = $dir;

上面添加如下代码:

// for SAE begin
$dir = SAE_DIR;
$url = SAE_URL;
//for SAE end

/** * Send a HTTP header to limit rendering of pages to same origin iframes.

的上面添加:

// for SAE begin
if ( !function_exists('utf8_encode') ) {
function utf8_encode($str) {
$encoding_in = mb_detect_encoding($str);
return mb_convert_encoding($str, 'UTF-8', $encoding_in);
}
}
//for SAE end

3.修改wp-admin/includes/file.php,注释掉如下代码:

// Set correct file permissions
//$stat = stat( dirname( $new_file ));
//$perms = $stat['mode'] & 0000666;
//@ chmod( $new_file, $perms );

OK,enjoy it!上传一张图片测试

使用七牛镜像存储功能为SAE上的WordPress加速 4K UHD超高清网络摄像机

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×