2011-10-17 54 views
0

我已經將jQuery Uploadify整合到我的WordPress插件中用於多個文件上傳。 Flash上​​傳表單生成的很好,我可以選擇文件並開始上傳。對於所有嘗試的文件,Uploadify都報告「HTTP錯誤」。使用onError()我看到它是錯誤404.Uploadify報告HTTP錯誤404,即使上傳成功

奇怪的是,文件上傳IS正在成功處理。新文件出現在我上傳的文件夾中,並創建數據庫記錄。那麼,爲什麼Uploadify報告失敗?

任何幫助,非常感謝。

這裏是我使用的代碼:

Uploadify JS

$(document).ready(function() { 
    $('#file_upload').uploadify({ 
    'scriptData': {'sid': '{$_REQUEST['gallery_uid']}'}, 
    'uploader' : '{$plugin_url}upif/uploadify.swf', 
    'script' : '{$plugin_url}upif.php', 
    'cancelImg' : '{$plugin_url}upif/cancel.png', 
    'auto'  : true, 
    'multi'  : true, 
    'simUploadLimit' : 3, 
    'fileExt' : '*.jpg;*.gif;*.png;*.zip', 
    'fileDesc' : 'Image Files' 
    }); 
}); 

Uploadify文件處理PHP

<?php 

@require_once('../../../wp-blog-header.php'); // Pull in WP functions in order to write to DB 

$uid = $_REQUEST['sid']; // Assigned Gallery UID 

if (!empty($_FILES)) { 
    $file_temp = $_FILES['Filedata']['tmp_name']; 
    $file_orig = basename($_FILES['Filedata']['name']) ; 

    $exts = explode('.', $file_orig); 
    $file_ext = strtolower('.' . $exts[count($exts)-1]); 

    $file_save = $uid . '_' . date('ymd') . time() . $exts[0] . $file_ext; 

    $upload_dir = wp_upload_dir(); 
    $target_path = $upload_dir['path'] . '/' . $file_save; 

    move_uploaded_file($file_temp, $target_path); // Move the file to WP's "uploads" path, using generated name 

    $insert = array(
    'guid'=> $uid, 
    'path'=> $file_save, 
    'sort_order'=> '0', 
    'date_created' => date('Y-m-d H:i:s') 
    ); 
    $wpdb->insert($wpdb->prefix . 'images', $insert); // Create DB record 

    echo '1'; // Success 
} 

解決:進一步的探索後,我能讓事情順利進行。 wp-blog-header.php include必須影響輸出。對我來說,解決方案是以不同的方式加入。

我刪除了包括在我的PHP處理程序的頂部,並用它代替:

<?php 

@require_once('../../../wp-config.php'); // Pull in WP config elements 
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions 
+0

那麼,這裏是真正的問題。該文件在那裏,但該程序錯誤地報告404 ...或程序報告該文件在一個位置,但你真的得到一個404錯誤應該是哪裏? – Sparky

+0

謝謝,Sparky - 問題在於,WP包含在某種程度上導致Uploadify JS錯誤地解釋了響應。文件位置似乎不是問題的一部分。 –

+0

請將該評論作爲下面的答案發布,並「接受」你自己的答案。你也會獲得一些代表點。 – Sparky

回答

1

進一步的探索後,我能得到的東西的工作。 wp-blog-header.php include必須影響輸出。對我來說,解決方案是以不同的方式加入。

我刪除了包括在我的PHP處理程序的頂部,並用它代替:

<?php 

@require_once('../../../wp-config.php'); // Pull in WP config elements 
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions