More About WordPress Uploads

昨天写了一篇Migrating WordPress Uploads,我意犹未尽。

每上传一个文件,WordPress会把它放在”Store uploads in this folder”指定的目录,但在post中都已转化成绝对路径来记录 Path 和 URL 。我不欣赏这种做法,因为这对服务器环境养成依赖。

WordPress核心对”Store uploads in this folder” 和 “Full URL path to files (optional)” 不重视,造成某些插件也无视这两个options的存在。比如WP Shopping Cart,根本不去探测这两个值,直接就把产品图片等文件保存位置设定为wp-content/uploads/wpsc/… 。

为了让WP Shopping Cart能够按照我的要求摆放文件,我只好修改了wp-shopping-cart.php,在 $upload_path 和 $upload_url 被调用之前,给它赋予正确的值。

$myuploads = wp_upload_dir();
$upload_path = $myuploads [‘basedir’];
$upload_url = $myuploads [‘baseurl’];

Leave a Reply

Your email address will not be published. Required fields are marked *