I've integrated jQuery Uploadify into my WordPress plugin for multiple file uploads. The Flash upload form is generated fine, and I'm able to select files and begin the upload. Uploadify is reporting "HTTP Error" for all files attempted. Using onError() I see it's error 404.
The strange thing is, the file upload IS being successfully processed. The new file appears in my uploads folder, and a database record is created. So, why is Uploadify reporting a failure?
Any help is very much appreciated.
Here is the code I'm using:
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 File Handler 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
}
SOLVED: After further exploration, I was able to get things working. The wp-blog-header.php include must have been affecting the output. The solution for me was to include in a different manner.
I removed the include at the top of my PHP handler, and replaced it with:
<?php
@require_once('../../../wp-config.php'); // Pull in WP config elements
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions
After further exploration, I was able to get things working. The wp-blog-header.php include must have been affecting the output. The solution for me was to include in a different manner.
I removed the include at the top of my PHP handler, and replaced it with:
<?php
@require_once('../../../wp-config.php'); // Pull in WP config elements
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions