Php 尝试上载图像时出现奇怪的问题

Php 尝试上载图像时出现奇怪的问题,php,wordpress,file-upload,image-uploading,Php,Wordpress,File Upload,Image Uploading,正在构建一个自定义上传表单(登录用户可在前端查看),该表单将直接将图像(仅图像)上传到wordpress媒体库(注意:不希望立即将其添加到特定的帖子id)。。。但我遇到了一个我似乎无法解决的问题 当用户登录到自定义页面时,他们会看到一个上载表单。。。选择他们想要上传的照片(使用wp默认上传限制参数…为upload\u max\u filesize 32M/max\u file\u uploads 20)并单击upload按钮后,表单重定向到上传脚本upload.php(重定向仅用于测试目的);现

正在构建一个自定义上传表单(登录用户可在前端查看),该表单将直接将图像(仅图像)上传到wordpress媒体库(注意:不希望立即将其添加到特定的帖子id)。。。但我遇到了一个我似乎无法解决的问题

当用户登录到自定义页面时,他们会看到一个上载表单。。。选择他们想要上传的照片(使用wp默认上传限制参数…为
upload\u max\u filesize 32M/max\u file\u uploads 20
)并单击
upload
按钮后,表单重定向到上传脚本
upload.php
(重定向仅用于测试目的);现在,问题是。。。在上载脚本的顶部(在包含所需的wp文件之后),我转储
$\u文件
数组,该数组在脚本的其余部分不运行任何内容的情况下返回以下内容:

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) } } }
所以,我想知道我的状态是不是做错了什么。。。因为就像我说的,这不是我的上传脚本,因为它甚至没有完成它的运行

这是我的代码

HTML表单(是的,您可以看到我在表单中使用了
enctype=“multipart/form data”

PHP upload script upload.PHP(仅运行的部分)

这就是它所说的关于tmp目录的
drwxrwxr-x


希望并祈祷有人知道如何解决这个问题。。。谢谢你的时间和帮助!:)

当你说
重定向到upload script upload.php(重定向仅用于测试目的)
这是什么意思?@SetSailMedia我的意思是我设置了表单
action
参数,以便重定向用于调试目的。。。但是,一旦一切正常,它将由ajax处理。对不起,我不太清楚。它能用一个小文件,比如说几KB吗?有趣的是,它为您构建了一个数组,让您知道有提交。不知何故,该文件没有写入临时文件夹。您是否可以在从浏览器访问的空白文件中使用
,查看PHP对
文件上传
最大文件上传
后最大文件大小
上传最大文件大小
内存限制
的配置,如果将
打印()
放在包含项上方,是否有任何更改?我想知道是不是有些WordPressInclude没有吃掉这个变量并对它做些什么。你的本地机器是Windows还是Linux?如果使用Windows,则可能是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();
});
<?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
cd /Applications/MAMP
ls -la