运行在SAE上的原版wordpress不支持图片和文件上传,需要修改代码。
1.在应用根目录下,创建sae.php文件:
<?php
/* 在SAE的Storage中新建的Domain名,比如“wordpress” */
define('SAE_STORAGE',wordpress);
/* 设置文件上传的路径和文件路径的URL,不要更改 */
define('SAE_DIR', 'saestor://'.SAE_STORAGE.'/uploads');
define('SAE_URL', 'http://'.$_SERVER['HTTP_APPNAME'].'-'.SAE_STORAGE.'.stor.sinaapp.com/uploads');
?>
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!上传一张图片测试
评论