Php Uploadify报告HTTP错误404,即使上载成功
我已经将jQuery Uploadify集成到我的WordPress插件中,用于多文件上传。Flash上传表单生成良好,我可以选择文件并开始上传。Uploadify正在报告所有尝试的文件的“HTTP错误”。使用onError()我看到了错误404 奇怪的是,文件上传正在成功处理中。新文件将显示在“我的上载”文件夹中,并创建数据库记录。那么,为什么Uploadify报告失败 非常感谢您的帮助 以下是我正在使用的代码: 上传JSPhp Uploadify报告HTTP错误404,即使上载成功,php,javascript,jquery,uploadify,Php,Javascript,Jquery,Uploadify,我已经将jQuery Uploadify集成到我的WordPress插件中,用于多文件上传。Flash上传表单生成良好,我可以选择文件并开始上传。Uploadify正在报告所有尝试的文件的“HTTP错误”。使用onError()我看到了错误404 奇怪的是,文件上传正在成功处理中。新文件将显示在“我的上载”文件夹中,并创建数据库记录。那么,为什么Uploadify报告失败 非常感谢您的帮助 以下是我正在使用的代码: 上传JS $(document).ready(function() {
$(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'
});
});
上载文件处理程序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处理程序顶部的include,并将其替换为:
<?php
@require_once('../../../wp-config.php'); // Pull in WP config elements
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions
<?php
@require_once('../../../wp-config.php'); // Pull in WP config elements
@require_once('../../../wp-includes/wp-db.php'); // Pull in WP DB functions
那么这里真正的问题是什么呢。文件在那里,但程序错误地报告了404。。。或者程序报告文件在一个位置,但是你真的在它应该在的位置出现了404错误?谢谢,Sparky-问题是WP include不知何故导致Uploadify JS误解了响应。文件位置似乎不是问题的一部分。请在下面将该评论作为答案发布,并“接受”您自己的答案。你也将获得一些代表积分。我第一次尝试,但它说我必须等待8小时:(奇怪的是,这将是所有事情中的404。你是否从另一个脚本中包含你的上传处理程序?如果是这样,请确保在上传处理程序脚本的末尾调用exit
,以防止代码进一步向下执行主脚本。