move_uploaded_file无法在wordpress文件夹中运行

问题描述 投票:0回答:1

我试图上传wordpress文件夹中的文件(wp-content / themes / twenty-12 / uploads /),每次提交表单时都会失败。

我的表单路径(wp-content / themes / twenty-12 / 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-12 / 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);
}

错误:bool(false)

注意:在完全许可的情况下,我已经检查了文件权限。我还检查了max.file_size_upload和php.ini的其他设置。

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

php wordpress file-upload
1个回答
0
投票

你应该使用WordPress助手

wp_upload_dir()

获取包含当前上载目录的路径和URL的数组。

wp_upload_dir()Determining Plugin and Content Directories

© www.soinside.com 2019 - 2024. All rights reserved.