2011-08-02 142 views
0

好吧,這讓我感到困惑。我的腳本在Mozilla中運行,但不是IE。我得到了IE此錯誤:僅在Internet Explorer中出現PHP錯誤

Warning: move_uploaded_file(uploads/properties/yh96gapdna8amyhhmgcniskcvk9p0u37/) [function.move-uploaded-file]: failed to open stream: Is a directory in /homepages/19/d375499187/htdocs/sitename/include/session.php on line 602 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpJkiaF3' to 'uploads/properties/yh96gapdna8amyhhmgcniskcvk9p0u37/' in /homepages/19/d375499187/htdocs/sitename/include/session.php on line 602 

我在session.php文件的代碼是:

function addPhoto($subphotoSize,$subphotoType,$subphotoTmpname,$subphotoDesc,$subfieldID,$subsessionid){ 
    global $database, $form; 

    /* Get random string for directory name */ 
    $randNum = $this->generateRandStr(10); 

    $maxFileSize = 2500000; // bytes (2 MB) 
    $filerootpath = PHOTOS_DIR.$subsessionid."/"; 
    if($subphotoType == "image/png"){ 
     $filename = $randNum.".png"; 
    } else if ($subphotoType == "image/jpeg"){ 
     $filename = $randNum.".jpg"; 
    } 
    $fullURL = $filerootpath.$filename; 

    /* Image error checking */ 
    $field = "photo"; 
    if(!$subphotoTmpname){ 
     $form->setError($field, "* No file selected"); 
    } else { 
     if($subphotoSize > $maxFileSize) { 
      $form->setError($field, "* Your photo is above the maximum of ".$maxFileSize."Kb"); 
     } else if (!is_dir($filerootpath)){ 
      mkdir($filerootpath,0777); 
      chmod($filerootpath,0777); 
     } 
     move_uploaded_file($subphotoTmpname, "$fullURL"); 
    } 
    /* Errors exist, have user correct them */ 
    if($form->num_errors > 0){ 
     return 1; //Errors with form 
    } else { 
     if($subfieldID == "1"){ // If the first field... 
      $is_main_photo = 1; 
     } else { 
      $is_main_photo = 0; 
     } 
     if(!$database->addNewPhoto($ownerID,$subphotoDesc,$fullURL,$userSession,$is_main_photo, $subsessionid)){ 
      return 2; // Failed to add to database 
     } 
    } 
    return 0; // Success 
} 

它創建的文件夾沒有問題,但沒有做任何事情。

+0

你可以打印'$ fullURL'並顯示輸出結果嗎? – PeeHaa

+0

你在傳遞這個函數是什麼?看看它們在兩個瀏覽器中是否有所不同。例如,如果您傳遞的是來自'$ _FILES'的文件名,請嘗試類似'var_dump($ _ FILES);'的方式查看IE和Firefox是否有區別。 –

+0

var_dump displays:array(1){[「photo」] => array(5){[「name」] => string(8)「6122.jpg」[「type」] => string(11)「image/pjpeg「[」tmp_name「] => string(14)」/ tmp/phpu8oMmx「[」error「] => int(0)[」size「] => int(493526) – user29660

回答

1

添加日誌消息以查看$ subphotoType的值。我的猜測是,當你從Internet Explorer上傳文件時,它既不是image/png也不是image/jpeg,在這種情況下,$ filename將是空的,因爲你沒有else子句。

if($subphotoType == "image/png"){ 
    $filename = $randNum.".png"; 
} else if ($subphotoType == "image/jpeg"){ 
    $filename = $randNum.".jpg"; 
} else { 
    // No else! $filename will be empty. 
} 

如果您正確調整錯誤報告設置,您應該看到一條通知,說您正在嘗試使用未定義的變量。

+0

我無所畏懼,沒有工作。我在表單中使用了JavaScript來防止其他文件類型。無論如何感謝 – user29660

+0

在客戶端,您可能正在檢查文件擴展名,並在服務器上檢查文件內容類型,這是另一回事。檢查並查看 - 添加一個else子句(「Got handled Content-Type:$ subphotoType」); – sagi

+0

你其實是對的,但其他條件沒有工作,因爲我正在上傳,不管那些if語句。謝謝 – user29660

相關問題