构建自定义上传表单(可在登录用户的前端查看),将图像(仅限图像)直接上传到wordpress媒体库(注意:不要立即将其添加到特定的帖子ID) ...但我遇到了一个似乎无法修复的问题。
当用户登录到自定义页面时,他们会在选择要上传的照片后使用上传表单(使用wp默认上传限制参数... {{1} })并单击表单重定向到上传脚本upload_max_filesize 32M / max_file_uploads 20
的{{1}}按钮(重定向仅用于测试目的);现在,这是问题...在我的上传脚本的顶部(刚刚包含所需的wp文件之后)我转储upload
数组,而不在脚本的其余部分运行任何内容返回以下内容:
upload.php
所以,我想知道我是否在表单中做错了...因为我说它不是我的上传脚本,因为它甚至没有完成它的运行。
这是我的代码
HTML表单(是的,您可以看到我在表单中使用$_FILES
)
array(1) { ["photos"]=> array(5) { ["name"]=> array(1) { [0]=> string(0) "" }
["type"]=> array(1) { [0]=> string(0) "" } ["tmp_name"]=> array(1) { [0]=>
string(0) "" } ["error"]=> array(1) { [0]=> int(4) } ["size"]=> array(1)
{ [0]=> int(0) } } }
JS(这就是制作“#pick-photos”点击“#file-upload”)
enctype="multipart/form-data"
PHP上传脚本upload.php(仅限正在运行的部分)
<form id="photo-upload" method="POST" action="<?php echo plugins_url( 'photo-uploadr/templates/upload.php' ); ?>" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="33554432" />
<input type="file" id="file-upload" name="photos[]" multiple />
<button type="button" class="btn" id="pick-photos"><?php _e( "Select Photos to Upload", "shorti" ); ?></button>
<ul id="file-uploads">
<!-- The file uploads will be shown here -->
</ul>
<button name="upload" id="upload" class="btn upload"><?php _e("Upload", "shorti"); ?></button>
</form>
当我检查这样的权限时:
jQuery('#pick-photos').click(function() {
jQuery('#file-upload').click();
});
这是关于tmp目录的<?php
// "/wordpress" added in front because of local host's DOCUMENT_ROOT being one directory short
require_once( $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-load.php" );
require_once( $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-admin/includes/media.php" );
require_once( $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-admin/includes/file.php" );
require_once( $_SERVER['DOCUMENT_ROOT'] . "/wordpress/wp-admin/includes/image.php" );
print_r( $_POST ); // Dumps the value of "MAX_FILE_SIZE"
var_dump( $_FILES );
if ( !$_FILES ) exit;
// Required for the wp_handle_upload() to upload the files
$upload_overrides = array( 'test_form' => false );
global $current_user;
get_currentuserinfo();
$logged_in_user = $current_user->ID;
// load up a variable with the upload directory
$uploads = wp_upload_dir();
var_dump( $uploads );
/** Since I'm doing this on localhost I figured I should add what this is returning
*
* array(6) { ["path"]=> string(62) "/Applications/MAMP/htdocs/wordpress/wp-content/uploads/2014/01"
* ["url"]=> string(58) "http://localhost:8888/wordpress/wp-content/uploads/2014/01"
* ["subdir"]=> string(8) "/2014/01"
* ["basedir"]=> string(54) "/Applications/MAMP/htdocs/wordpress/wp-content/uploads"
* ["baseurl"]=> string(50) "http://localhost:8888/wordpress/wp-content/uploads"
* ["error"]=> bool(false) }
*/
foreach ( $_FILES['photos']['error'] as $key => $error ) {
if ( $error === UPLOAD_ERR_OK ) { // Not passing here because $_FILES is receiving error #4
所说的
希望并祈祷有人知道如何解决这个问题...感谢您的时间和任何帮助! :)