【问题标题】:move_uploaded_file not working in wordpress foldermove_uploaded_file 在 wordpress 文件夹中不起作用
【发布时间】:2019-02-09 13:58:08
【问题描述】:

我正在尝试将文件上传到 wordpress 文件夹 (wp-content/themes/twenty-twelve/uploads/) 中,每次提交表单时都会失败。

我的表单路径(wp-content/themes/twenty-twelve/template-parts/form.php)

<form id="Form" method="post" action="/checkout/" enctype='multipart/form-data'>
<input type="file" name="image">
<input type="submit" name="submit" value="Proceed to Payment" id="FormSubmit" />
</form>

Checkout.php 路径(wp-content/themes/twenty-twelve/template-parts/checkout.php)

if(isset($_POST['submit'])){

$Image   = $_FILES['image']['name'];
$Image  = implode(",",$_FILES['image']['name']);

$thisFile = $_FILES['image'];
$Image = $_FILES['image']['name'];
$FileTmp = $thisFile['tmp_name'][0];

$sFileTypeArr= explode(".",$Image );
$sFileType = end($sFileTypeArr);
$randNo = date("ydhis");
$ImageFinal = "IMG_".$randNo.".".$sFileType;

$url = '/wp-content/themes/twenty-twelve';
$fileSavePath = $url."/uploads/";

$ImageFinalWithPath = $fileSavePath.$ImageFinal;
$upload_file = move_uploaded_file($_FILES['image']['tmp_name'], $ImageFinalWithPath);

var_dump($upload_file);
}

错误:布尔(假)

注意:我已经检查了文件权限,并获得了完全权限。我还检查了 php.ini 的 max_file_size_upload 和其他设置。

我正在尝试一次上传一个文件。它显示错误 bool(false)

【问题讨论】:

  • 你试过 $upload_file = move_uploaded_file($FileTmp, $ImageFinalWithPath);代替 $upload_file = move_uploaded_file($_FILES['image']['tmp_name'], $ImageFinalWithPath); ???
  • 第二次尝试 $url 的绝对路径,因为您的 Checkout.php 位于 (wp-content/themes/twenty-twelve/template-parts/) 文件夹中

标签: php wordpress file-upload


【解决方案1】:

你应该使用 WordPress 助手

wp_upload_dir()

获取一个包含当前上传目录路径和url的数组。

请参阅 wp_upload_dir()Determining Plugin and Content Directories

【讨论】:

    猜你喜欢
    • 2019-05-09
    • 1970-01-01
    • 2012-04-14
    • 2016-03-11
    • 2016-06-12
    • 2018-07-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-01
    相关资源
    最近更新 更多