2013-01-01 3 views
-1

이 스크립트에 문제가 있습니다. 헤더 리다이렉트는 호출되지 않지만 MySQL 쿼리는 않습니다.json이 PHP 헤더를 호출했습니다.

MySQL 쿼리가 호출되고 헤더가 이상하지 않으므로 이상하게 보입니다. 난 당신이 다른 페이지로 호출 클라이언트를 리디렉션 할 있으리라 믿고있어 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; 
      } 
     } 
    }); 
}); 
+1

'AJAX'로 업로드하는 경우 리디렉션하지 않아야합니다. –

+0

이 http://pastebin.com/yyfddgD5는 전체 스크립트이며, jQuery.filedrop.js도 사용하고 있습니다. –

+0

헤더가 호출되지 않는다고 어떻게 말할 수 있습니까? MySQL 쿼리에 오류가 있거나 무엇 때문에? - 좋아, 일하지 말라 = 질문이 아니야. 코드 옆에 아무 것도 제공 할 수없는 경우를 제외하고는 닫을 투표를 할 것입니다. – hakre

답변

2

호출

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(); 

    } 

} 

를 그리고 자바 스크립트 :

PHP 리디렉션해야 스크립트? 글쎄, 당신은 자바 스크립트를 통해 서버에서받은 응답에 따라 행동해야합니다. 귀하의 브라우저가 JS를 통해 요청하는 페이지에 실제로 "가"이 아니기 때문에, 재 작성된 헤더는 클라이언트의 위치에 영향을 미치지 않습니다.

당신은

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

자바 스크립트를 통해 리디렉션 할 수 있습니다.

희망이 있습니다.

+0

여전히 작동하지 않습니다. –

+1

'window.location'을 사용하지 마십시오. 객체이며, js로 리디렉션하는 데 사용할 수있는 속성 ('href') 및 메서드 ('replace()')가 있습니다. –

+0

둘 다 시도했는데 작동하지 않습니다 –

관련 문제