我在Wordpress插件中使用FineUploader:
require_once($_SERVER['DOCUMENT_ROOT']. '/wp-load.php');
include_once($_SERVER['DOCUMENT_ROOT']. '/wp-admin/includes/media.php');
include_once($_SERVER['DOCUMENT_ROOT']. '/wp-admin/includes/file.php');
include_once($_SERVER['DOCUMENT_ROOT']. '/wp-admin/includes/image.php');
if(!$_FILES) exit();
if(isset($_FILES['qqfile'])) {$files = $_FILES['qqfile'];}
$upload_dir = wp_upload_dir();
$file_name = $files['name'];
$file_name = $upload_dir['path'] . '/' . basename($file_name);
$upload_overrides = array( 'test_form' => false );
$file_post = wp_handle_upload($files,$upload_overrides); //Posts File
$file_link = $file_post['file'];
$file_type = wp_check_filetype(basename($file_link), null); //File Extension
$post_name = preg_replace('/\.[^.]+$/', '', basename($file_link)); //Post Name
$attachment = array(
'guid' => $file_link,
'post_mime_type' => $file_type['type'],
'post_title' => $post_name,
'post_content' => '',
'post_status' => 'inherit'
);
$attach_id = wp_insert_attachment($attachment, $file_name, $_POST['post_id']);
$attach_data = wp_generate_attachment_metadata($attach_id, $file_name);
$attach_final = wp_update_attachment_metadata($attach_id, $attach_data);
$response['data'] = $_FILES;
$response['success'] = 'true';
echo json_encode($response);
exit();
当我仅上传一个文件时,此代码可以正常工作。当我拖放多个文件时,上传失败(文件根本没有上传)。
我的FineUploader代码是:
$("#fine-uploader").fineUploader({
debug: true,
request: {
endpoint: Ajax.ajaxurl,
params: {
action: 'attach_files',
post_id: $('#post_id').val()
}
},
deleteFile: {
enabled: true,
endpoint: '/uploads'
},
retry: {
enableAuto: true
}
});
我做错了什么?
编辑:根据评论,回复是:
[FineUploader 4.2.2] responseText = {"data":{"qqfile":{"name":"6-7-8.JPG","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpGI9bVU","error":0,"size":135947}},"success":"true"} jquery.fineuploader.min.js?ver=3.9:16
[FineUploader 4.2.2] Received response status 200 with body: {"data":{"qqfile":{"name":"6-7-8.JPG","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpGI9bVU","error":0,"size":135947}},"success":"true"} jquery.fineuploader.min.js?ver=3.9:16
XHR finished loading: POST "http://domain.com/wp-admin/admin-ajax.php". jquery.fineuploader.min.js?ver=3.9:18
[FineUploader 4.2.2] xhr - server response received for 1 jquery.fineuploader.min.js?ver=3.9:16
[FineUploader 4.2.2] responseText = {"data":{"qqfile":{"name":"26feb-jazz (1).jpg","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpROrYrz","error":0,"size":75475}},"success":"true"} jquery.fineuploader.min.js?ver=3.9:16
[FineUploader 4.2.2] Received response status 200 with body: {"data":{"qqfile":{"name":"26feb-jazz (1).jpg","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpROrYrz","error":0,"size":75475}},"success":"true"} jquery.fineuploader.min.js?ver=3.9:16
XHR finished loading: POST "http://nevestam.cz/wp-admin/admin-ajax.php". jquery.fineuploader.min.js?ver=3.9:18
[FineUploader 4.2.2] xhr - server response received for 2 jquery.fineuploader.min.js?ver=3.9:16
[FineUploader 4.2.2] responseText = {"data":{"qqfile":{"name":"Anna Garcia.jpg","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpIDGCUh","error":0,"size":254890}},"success":"true"} jquery.fineuploader.min.js?ver=3.9:16
[FineUploader 4.2.2] Received response status 200 with body: {"data":{"qqfile":{"name":"Anna Garcia.jpg","type":"image\/jpeg","tmp_name":"\/home\/www\/domain.com\/tmp\/phpIDGCUh","error":0,"size":254890}},"success":"true"}
答案 0 :(得分:0)
想出来 - 似乎问题出现在
中$file_name = $files['name'];
我把它改成了
$file_name = sanitize_file_name($files['name']);
现在正在运作。我不知道这与单一和多重上传有什么关系。