2012-02-13 19 views
0

這是我的圖片上傳代碼並且頭不起作用,它停留在此頁面上。頭不起作用,很確定在調用之前沒有輸出

<?php 
if ($_FILES ["file"]["type"] == "image/jpeg") { 
    if ($_FILES ["file"]["error"] > 0) { 
     header ("index.php?s=2"); 
    } else { 
     if ($dir = opendir ('Images')) { 
      readdir ($dir); 
      readdir ($dir); 
      $count = 0; 

      while (false !== ($image = readdir ($dir))) { 
       $count++; 
      } 

      move_uploaded_file ($_FILES ["file"]["tmp_name"], "Images/" . ($count + 1) . ".jpg"); 
      header ("index.php?s=0"); 
     } 
    } 
} else { 
    header ("index.php?s=1"); 
} 
?> 

我讀

記住header()函數被髮送任何實際輸出之前,必須被調用,或者通過正常的HTML標記,在一個文件中的空行,或從PHP。使用include()或require()函數或其他文件訪問函數讀取代碼,並在調用header()之前輸出空格或空行是非常常見的錯誤。使用單個PHP/HTML文件時存在同樣的問題。

從PHP手冊,但我不認爲我有任何產出。

+0

哪裏是你的html,head標籤e.t.c? – 2012-02-13 06:23:39

+0

標題(「location:index.php?s = 0」); – 2012-02-13 07:00:54

回答

4

重定向的正確方法,

header("Location:index.php?s=0"); 
+0

就是這樣,謝謝。 – TreeTree 2012-02-13 13:49:08

2

這不是一個有效的標題。也許你打算迴應一個Location header