2011-04-13 73 views
7

我正在運行一個腳本,它移動上傳文件時使用move_uploaded_file()。我已經做了這麼多次,但由於某種原因,它無法正常工作。我已經confimred如下:使用method="post"和正確enctypemove_uploaded_file不起作用,沒有錯誤

  1. <form>
  2. 從形式引用
  3. 正確的文件
  4. 目錄有權限777
  5. 所有memory_limitmax_execution_time等被設置爲超高設置避免超時

基本上,下面的腳本返回只有Your image is too big.。我還啓用了所有錯誤顯示,但仍然沒有出現錯誤。有任何想法嗎?

$time = time(); 
$target_path = "/absolute/path/to/temp/directory/temp/"; 

$target_path = $target_path.$time.'.jpg'; 

if(move_uploaded_file($_FILES['image']['tmp_name'], $target_path)) {    

} else{ 
     $error .= '<li>Your image is too big.</li>'; 
} 

使用的1and1與php.ini的黑客主機:P

更新1

我想從腳本發生正好60秒後補充一點反應。

更新2

我們可能會用這個地方得到。只是print_r($_FILES)這是陣列的結果:

Array ( 
    [image] => Array ( 
     [name] => P2120267.JPG 
     [type] => 
     [tmp_name] => 
     [error] => 1 
     [size] => 0 
    ) 
) 

所以這使我相信該文件無法正確上傳到服務器或什麼?我已檢查併發布表格是<form action="" method="post" enctype="multipart/form-data">。那麼,從我所知道的情況來看,文件沒有被上傳到服務器的臨時區域?

UPDATE 3

上述陣列中的注意的[error] => 1。這顯然低至the filesize being larger than the upload_max_filesize。但是,當我將此設置爲128M時,我在60秒後出現白屏。我上傳的文件2.5MB

這裏是我的php.ini文件:

register_globals=off 
memory_limit = 128M 
max_execution_time=3600 
post_max_size = 128M 
upload_max_filesize= 128M 

UPDATE 4

通過上面的詳細信息,看來我得到一個WSOD,但圖像正在上傳。那麼,如何阻止WSOD?我找不到任何相關的錯誤。

UPDATE 5 - FOUND IT!

對我沒有給你們所有的代碼感到羞恥。它看起來像它與這條線做:

resizeImage($feedBurnerStatsSource, PHOTOMSGDIR.'temp/'.$time.'-tmp.jpg',$width,$height); 

在下面的代碼:

function resizeImage($source, $destination = NULL,$wdt, $height = NULL){ 
    if(empty($height)){ 
      // Height is nit set so we are keeping the same aspect ratio. 
      list($width, $height) = getimagesize($source); 
      if($width > $height){ 
        $w = $wdt; 
        $h = ($height/$width) * $w; 
        $w = $w; 
      }else{ 
        $w = $wdt; 
        $h = $w; 
        $w = ($width/$height) * $w; 
      } 
    }else{ 
      // Both width and Height are set. 
      // this will reshape to the new sizes. 
      $w = $wdt; 
      $h = $height; 
    } 
    $source_image = @file_get_contents($source) or die('Could not open'.$source); 
    $source_image = @imagecreatefromstring($source_image) or die($source.' is not a valid image'); 
    $sw = imagesx($source_image); 
    $sh = imagesy($source_image); 
    $ar = $sw/$sh; 
    $tar = $w/$h; 
    if($ar >= $tar){ 
      $x1 = round(($sw - ($sw * ($tar/$ar)))/2); 
      $x2 = round($sw * ($tar/$ar)); 
      $y1 = 0; 
      $y2 = $sh; 
    }else{ 
      $x1 = 0; 
      $y1 = 0; 
      $x2 = $sw; 
      $y2 = round($sw/$tar); 
    } 
    $slate = @imagecreatetruecolor($w, $h) or die('Invalid thumbnail dimmensions'); 
    imagecopyresampled($slate, $source_image, 0, 0, $x1, $y1, $w, $h, $x2, $y2); 
    // If $destination is not set this will output the raw image to the browser and not save the file 
    if(!$destination) header('Content-type: image/jpeg'); 
    @imagejpeg($slate, $destination, 75) or die('Directory permission problem'); 
    ImageDestroy($slate); 
    ImageDestroy($source_image); 
    if(!$destination) exit; 
    return true; 
} 

所以,WSOD意味着它沒有消息的某種死亡。有任何想法嗎?

+1

嘗試'print_r($ _ FILES);'查看完整的FILES數組。它可能包含錯誤代碼。你的錯誤信息並沒有真正有意義,因爲你沒有做大小檢查,*每個錯誤條件都會返回「圖像太大」 – 2011-04-13 21:33:07

+0

文件名可能無效。該文件密鑰集? – 2011-04-13 21:33:27

+0

如果你沒有得到任何錯誤消息,請嘗試'copy()'而不是'move_uploaded_file()'。在這種情況下也可以看一下'error.log'。 – mario 2011-04-13 21:34:02

回答

9

只是爲了驗證是​​設置爲高水平?根據php.net因爲:

如果POST數據的大小大於post_max_size中,$ _ POST和$ _FILES superglobals便會爲空。這可以以各種方式進行跟蹤,例如,通過將$_GET變量傳遞給處理數據的腳本,即<form action="edit.php?processed=1">,然後檢查是否設置了$_GET['processed']

需要考慮的事情。

更多信息見this link和向下滾動到​​部分

UPDATE

以我的經驗,如果你得到一個WSOD它通常做error_reportingdisplay_errors被關閉或memory_limit達到。在頂部的腳本,我通常設置memory_limit到1024M,以確認是不是該問題,並error_reportingdisplay_errors轉彎......這樣的文件上傳之前把這個:

error_reporting(E_ALL); // or E_STRICT 
ini_set("display_errors",1); 
ini_set("memory_limit","1024M"); 

通常出手的WSOD,並給你和錯誤的工作。

UPDATE

你試過取下@錯誤抑制的所有功能前,看看他們生產的特定錯誤?你還有什麼是執行和輸入超時?你可以驗證哪些頭文件正在發送? (確保它是Content-Type=text/html;

+0

是的,其設置爲256M。當我補充說60秒後我得到了「死亡白屏」。 – David 2011-04-14 06:51:02

+0

看到上面的更新,你可能會找到一些東西。 – David 2011-04-14 07:09:55

+0

完成了所有這些,仍然沒有錯誤,仍然得到相同的錯誤= 1 – David 2011-04-14 16:54:09

3

嘗試將目標路徑更改爲非臨時目錄。

後這裏的一些更新的是分辨率:

set_time_limit(0); 
ini_set('upload_max_filesize', '500M'); 
ini_set('post_max_size', '500M'); 
ini_set('max_input_time', 4000); // Play with the values 
ini_set('max_execution_time', 4000); // Play with the values 

...添加到你的文件的開頭處理該上傳。

+0

它上傳到的臨時目錄是我自己創建的目錄,而不是系統臨時目錄。 – David 2011-04-14 06:51:34

+0

您是否嘗試添加上述內容?該設置適用於所有上傳位置。 – 2011-05-09 14:35:09

+0

您的代碼有效。謝謝 – 2016-11-28 03:16:01

0

上週我有同樣的問題,這只是因爲我的服務器空間磁盤已滿!我希望它會幫助別人...

0

我有同樣的問題,但我想覆蓋一個文件,所以我必須刪除舊文件,而不是它的工作原理。