PHP头由json调用


PHP Header called by json

我对这个脚本有一个问题,头重定向没有被调用,但MySQL查询。

它看起来很奇怪,我MySQL查询得到调用和头没有?

PHP脚本应该重定向:
if (array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ) {
    $pic = $_FILES['pic'];
    if (!in_array(get_extension($pic['name']),$allowed_ext)) {
        exit_status('Only '.implode(',',$allowed_ext).' files are allowed!');
    }   
    // Move the uploaded file from the temporary 
    // directory to the uploads folder:
    if (move_uploaded_file($pic['tmp_name'], $upload_dir.$key.'-'.$pic['name'])) {
        $name = $key.'-'.$pic['name'];
    $query = "INSERT INTO `uploads` (id, file_name, up_date, rm_date) VALUES ('$id', '$name', '$up_date', '$rm_date')"; 
    mysql_query($query) or die(mysql_error()); // **Get called**
    header("Location: download.php?id=$id"); // **Does not get called**
    exit();
    }
}
而Javascript调用PHP脚本
$(function(){
    var dropbox = $('#dropbox'),
        message = $('.message', dropbox);
    dropbox.filedrop({
        // The name of the $_FILES entry:
        paramname:'pic',
        maxfiles: 1,
        maxfilesize: 25,
        url: 'upload.php',
        uploadFinished:function(i,file,response){
            $.data(file).addClass('done');
            // response is the JSON object that upload.php returns
        },
        error: function(err, file) {
            switch(err) {
                case 'BrowserNotSupported':
                    showMessage('Your browser does not support HTML5 file uploads!');
                    break;
                case 'TooManyFiles':
                    alert('Too many files! Only one at same time is allowed.');
                    break;
                case 'FileTooLarge':
                    alert(file.name+' is too large! Please upload files up to 25mb.');
                    break;
                default:
                    break;
            }
        },
        // Called before each upload is started
        beforeEach: function(file) {
            if(!file.type.match(/^image'//)) {
                alert('Only images are allowed!');
                // Returning false will cause the
                // file to be rejected
                return false;
            }
        }
    });
}); 

我假设您希望将调用客户端重定向到另一个页面?这里,您必须通过JavaScript来实现,对从服务器接收到的响应进行操作。因为你的浏览器实际上并没有"go"到你通过JS请求的页面,所以重写的标头不会影响你的客户端的位置。

可以用

window.location = "http://www.example.com/"

通过JavaScript重定向。

希望对你有帮助。