我需要将徽标上传功能添加到WordPress上的自定义php插件。 我发现WordPress的抄本此代码:无法使用wordpress上传功能上传文件
if (! function_exists('wp_handle_upload')) require_once(ABSPATH . 'wp-admin/includes/file.php');
$uploadedfile = $_FILES['editfile'];
$upload_overrides = array('test_form' => false);
$movefile = wp_handle_upload($uploadedfile, $upload_overrides);
if ($movefile) {
echo "File is valid, and was successfully uploaded.\n";
var_dump($movefile);
} else {
echo "Possible file upload attack!\n";
}
下面的形式:
<form action="' . site_url('/edit-company/?cid=' . $_GET['cid']) . '" method="post">
<label><b>Company Name:</b></label> <input type="text" name="editname" value="' . $company->company_name . '">
<label><b>Address:</b></label> <input type="text" name="editaddress" value="' . $company->company_address . '">
<label><b>Telephone:</b></label> <input type="text" name="edittelephone" value="' . $company->company_telephone . '">
<label><b>Fax:</b></label> <input type="text" name="editfax" value="' . $company->company_fax . '">
<label><b>Email:</b></label> <input type="text" name="editemail" value="' . $company->company_email . '">
<label><b>Website:</b></label> <input type="text" name="editwebsite" value="' . $company->company_website . '">
<label><b>Logo:</b></label> <input type="file" name="editfile" id="file">
<input type="submit" value="Submit">
</form>
如果我将文件提交到这一点,使我有以下错误:
File is valid, and was successfully uploaded. array(1) { ["error"]=> string(212) "File is empty. Please upload something more substantial. This error could also be caused by uploads being disabled in your php.ini or by post_max_size being defined as smaller than upload_max_filesize in php.ini." }
的我提交的文件大小约为50kb。上传更大或更小的文件似乎没有什么区别。
我没有问题上传WordPress的任何大小的文件管理员我不会认为php.ini或张贴大小是造成这种情况。
如果您对此有任何提示或信息,请让我知道。我现在已经停留了很长一段时间了。尝试在香草PHP中使用简单的上传脚本,但这似乎并没有工作,所以我回来试图用wp函数完成它。
更新: - 试着上传文件夹的权限设置为777 - 没有帮助
我认为你需要,你要上传的文件对文件夹的权限。 –
将wp uploads文件夹的权限设置为775是否安全? –
是的,它可以安全地设置权限775. –