drne47241 2015-01-12 14:19
浏览 55
已采纳

获取服务器wordpress上的当前路径

Today I am adding a custom code to wordpress page.php to manage form data including file upload. I just want to check the real page so I can give the path to upload the file in code.

I have this code to upload the file:

$target = "uploads/"; 
$target = $target . basename($_FILES['pass_doc']['name']); 
//Here we check that $ok was not set to 0 by an error 
move_uploaded_file($_FILES['pass_doc']['tmp_name'], $target);
$pass_doc = $_FILES['pass_doc']['name'];

But I don't know target path should I give I tried:

$target = "example.org/uploads/";

But its also not working for me. Please give any suggestions.

Thanks

  • 写回答

1条回答 默认 最新

  • doudao8283 2015-01-12 14:24
    关注

    The problem is, when you says uploads/, that will be always a relative path to your current directory. Use the wordpress wp_upload_dir() function. Check the documentation here

    $upload_dir = wp_upload_dir();
    $target = $upload_dir['baseurl'] . "/" . basename($_FILES['pass_doc']['name']); 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号