2011-03-22 63 views
0
Warning: fopen() expects parameter 1 to be string, array given in /home/speedycm/public_html/speedyautos/carphoto.php on line 42 

Warning: filesize() [function.filesize]: stat failed for Array in /home/speedycm/public_html/speedyautos/carphoto.php on line 43 

Warning: fread(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 43 

Warning: fclose(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 44 

每當試圖在我的網站上上傳圖片時我都會收到這些錯誤消息,而且我不知道如何將它們整理出來。任何人都可以請幫忙?線36-59讀:嘗試上傳圖片時重複發出警告

$CarInfo->Load(); 
if ($hidaction == "addphoto") 
{ 
    $ctrP = 0; 
    foreach ($_FILES['pics'] as $pics) 
    { 
     if ($_FILES['pics']['name'][$ctrP] <> "") 
     { 
      if (is_uploaded_file($_FILES['pics']['tmp_name'][$ctrP]) or die("No Image: " . $_FILES['pics']['name'][$ctrP])) 
      { 
       $ext = substr(strrchr($_FILES['pics']['name'][$ctrP], "."), 1); 
       $fp = fopen($_FILES["pics"]["tmp_name"], 'rb'); 
       $contents = fread($fp, filesize($_FILES["pics"]["tmp_name"])); 
       fclose($fp); 
       if (preg_match("/system/", $contents) OR preg_match("/<\?/", $contents)) 
       { 
        $error .= "Invalid image: {$_FILES['pics']['name'][$ctrP]}<br />"; 
        //$pieces = explode(".", $_FILES['pics']['name'][$ctrP]); 
        //$ext = $pieces[count($pieces) - 1]; 
       } elseif ((in_array($ext, $types_array)) AND ($_FILES['pics']["size"][$ctrP] < (MAXFILE_SIZE * 1000000))) 
       { 
        $orgImageName = "cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]); 
        $thmImageName = "thumb_cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]); 
        $dtlImageName = "dtl_cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]); 

提前很多感謝和抱歉野生壓痕BTW :-)

+1

我改進了你的野生縮進。 – Anomie 2011-03-22 02:19:52

+0

謝謝!你是怎麼做到的? – methuselah 2011-03-22 02:30:36

+1

縮進4個空格。沒有標籤。 – Anomie 2011-03-22 02:31:21

回答

2

我不是一個PHP的人,但在我看來,就好像_FILES是三字符串的三維數組。有時候你使用三個指標:

$ _FILES [ '圖片'] [ 'tmp_name的值'] [$ CTRP]

但在fopen()調用,你只使用兩個;這意味着你將一個字符串數組傳遞給fopen(),這是錯誤的。您需要在此行上的第三個索引:

$ fp = fopen($ _ FILES [「pics」] [「tmp_name」],'rb');

1

您忘記正確引用加載到導致錯誤的行中上傳的$ _FILES數組中的多個圖像。

如果您有:

$fp = fopen($_FILES["pics"]["tmp_name"], 'rb'); 
$contents = fread($fp, filesize($_FILES["pics"]["tmp_name"])); 

應該是這樣的:

$fp = fopen($_FILES["pics"]["tmp_name"][$ctrP], 'rb'); 
$contents = fread($fp, filesize($_FILES["pics"]["tmp_name"][$ctrP])); 

什麼你發送是一個數組($_FILES["pics"]["tmp_name"])成需要一個字符串的函數,這應該是值從陣列中撥下($_FILES["pics"]["tmp_name"][$ctrP])。

相關問題