2010-03-05 8 views
0

나는이 스크립트가 어젯밤에 잘 작동한다고 맹세했지만 오늘은 작동하지 않습니다. foreach 루프 내부에 들어가는 것은 아닙니다. 이유를 모르겠습니다. 파일을 선택하고 제출을 클릭하더라도 $ _FILES 배열은 null입니다.PHP가 foreach 루프에 들어 가지 않음

기본적으로이 스크립트는 파일 입력 태그가 있고 jquery를 사용하여 사용자가 파일을 선택하면 다른 파일 입력 태그를 추가합니다. 제출 버튼을 클릭하면 PHP가 호출됩니다.

<?php 
//used for firePHP 
include('PHP/FirePHPCore/fb.php'); 
ob_start(); 


$success = false; 
$error = ""; 
$allowable_types = array(
    'image/jpeg', 
    'image/pjpeg', 
    'image/jpg', 
    'image/jpe', 
    'image/gif', 
    'image/png' 
); 



################################################################# 
//NOT GETTING INSIDE THE FOREACH LOOP. $_FILES array is always null 
################################################################## 
//loops through the files that the user has chosen to be uploaded them and moves them to the Images/uploaded folder 
foreach($_FILES as $key => $value) { 
    if(!empty($_FILES[$key])) { 
     if($_FILES[$key]['error'] == 0) { 
      if(in_array($_FILES[$key]['type'], $allowable_types) && ($_FILES[$key]['size'] < 5000000)) { 
       if(!file_exists("Images/uploaded/".$_FILES[$key]['name'])) { 
        move_uploaded_file($_FILES[$key]['tmp_name'], "Images/uploaded/".$_FILES[$key]['name']); 
        $success = true; 
       } else { 
        $error = "<h3 class=\"bad\">At least one of the files already exists</h3>"; 
       } 
      } else { 
       $error = "<h3 class=\"bad\">At least one of the files you've selected is either too large or not the correct file type</h3>"; 
      } 
     } elseif($_FILES[$key]['error'] == 4) { 

     } else { 
      $error = "<h3 class=\"bad\">An error occurred while trying to upload one of the files</h3>"; 
     } 
    } else { 
     $error = "<h3 class=\"bad\">You need to select a file</h3>"; 
    } 
} 



?> 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<meta http-equiv="refresh" content="1205"> 
<link rel="stylesheet" type="text/css" href="CSS/reset.css" /> 
<link rel="stylesheet" type="text/css" href="CSS/uploadFile.css" /> 
<link rel="stylesheet" type="text/css" href="CSS/galleria.css" /> 
<script type="text/ecmascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> 
<script type="text/javascript" src="JS/galleria.jquery.js"></script> 

<script type="text/javascript"> 


    $(document).ready(function() { 

     var i = 1; 

     //gives the first li the class .active so that it shows the large version as if it's been clicked. 
     //-- used for the gallery page 
     $('#content ul.gallery li:first-child').addClass('active'); 

     //fades the links on hover -- used for the nav links 
     $('#header ul li a').hover(function() { 
      $(this).fadeTo(300, 0.3); 
     },function() { 
      $(this).fadeTo(300, 1); 
     }); 



      $('input:file:last').live('change',function() { 
       var file = $(this).val(); 
       if(file !== null && file !== "") { 
        if(i < 6) { 
         $(this).after("<input type=\"file\" name=\"uploadedFile"+i+"\" value=\"\" />"); 
         i++; 
        } 
       } 
      }); 
    }); 
</script> 
<meta name="keywords" content="Steph Mcclisch Photography Portfolio Pictures" /> 
<title>Steph McClish Photography</title> 
</head> 

<body> 
<div id="floater"></div> 
<div id="wrapper"> 

    <div id="content"> 
     <?php 
     if($success) { 
     echo "<h3 class=\"good\">Files Uploaded Successfully!</h3>"; 
     } elseif ($error) { 
     echo $error; 
     } 
    ?> 
     <h4>Choose the files to be uploaded</h4> 
     <form action="<?php $_SERVER['PHP_SELF']?>" method="post" enctype="multipart/form-data"> 
      <input type="hidden" name="MAX_FILE_SIZE" value="500000" /> 
      <input type="file" name="uploadedFile0" value="" /> 
      <button type="submit" name="login">Submit</button> 
     </form> 
     <h5><a href="PHP/Manage.php">Manage Files/Folders</a></h5> 
    </div> 


</div> 
</body> 
</html> 

답변

1

모두 내 Wamp 서버 설정과 관련이 있습니다. 메뉴 바의 wamp 아이콘에서 나는 php> php settings> file uploads로 갔다. 한번 클릭하면 모든 것이 해결되었습니다.

+0

해결 방법이 맞으면이 대답을 수락하십시오. –

+0

2 일 동안 고객님의 답변을 수락 할 수 없습니다. – Catfish

1

Windows XP, SP2에서는 Explorer가 때때로 확장명없이 파일을 업로드하지 못합니다.

$ _FILES 배열은 null입니다. Microsoft는 보안 기능을 말합니다 (!)

유일한 해결책은 업로드 된 파일에 확장명을 적용하는 것입니다.

관련 문제