WordPress的PHP上传问题 - >想上传到主题目录,但功能是管理员目录的本地

时间:2011-02-21 23:23:46

标签: php wordpress file-upload

我正在尝试在WP functions.php中编写一个上传函数。它工作得很好,将文件上传到wp-admin,我希望它进入主题目录 - 我可以使用get_bloginfo访问...但这是一个绝对的地址。

有没有办法将文件上传到同一站点但不是同一目录的目录?

文件结构如下

wp-admin
wp-content
   themes
     Mytheme

该功能在wp-admin中运行,但我想让它进入我的主题。

  $target_path = get_bloginfo('template_url');//NOT WORKING ABSOLUTE PATH

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
    echo(">> " . $target_path . " <<");
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";

} else{
    echo "There was an error uploading the file, please try again!";
}

2 个答案:

答案 0 :(得分:1)

将get_bloginfo()与stylesheet_directory参数一起使用。

请参阅:http://codex.wordpress.org/Function_Reference/get_bloginfo#Template_Directory以供参考。

尝试修改您的代码:

 $target_path = get_bloginfo('stylesheet_directory');

答案 1 :(得分:0)

只是一个补充:大部分时间你应该将上传的文件存储在配置的上传文件夹中 - 通过http://codex.wordpress.org/Function_Reference/wp_upload_dir获取