2010-01-27 7 views
0

다중 파일 업 로더를 만들려고합니다.
"Multiple File Upload Magic With Unobtrusive Javascript"jquery, PHP 배열 문제가있는 여러 파일 업로드

업로드 된 파일이 없습니다. 나는 이것이 배열에 파일을 넣었 기 때문에 PHP가 배열을 처리하도록 설정되어 있지 않기 때문에 이것이 확실하다고 확신한다. (나는 어떻게 해야할지 모른다.) 내가 뭘 잘못하고 있는지에 대한 도움이 필요 하신가요?

미리 감사드립니다. :)

jQuery 코드


$(document).ready(function(){ 
    var fileMax = 12; 
    $('#element_input').after('<div id="files_list"></div>'); 
     $("input.upload").change(function(){ 
      doIt(this, fileMax); 
     }); 
    }); 

    function doIt(obj, fm) { 
     if($('input.upload').size() > fm) {alert('Max files is '+fm); obj.value='';return true;} 
      $(obj).hide(); 
      $(obj).parent().prepend('<input type="file" class="upload" name="fileX[]" />').find("input").change(function() {doIt(this, fm)}); 
     var v = obj.value; 
     if(v != '') { 
      $("div#files_list").append('<div>'+v+'<input type="button" class="remove" value="" /></div>') 
      .find("input").click(function(){ 
      $(this).parent().remove(); 
      $(obj).remove(); 
      return true; 
     }); 
    } 
}; 

HTML 코드


<form action="myPhpCodeIsBelow.php" method="post" enctype="multipart/form-data" name="asdf" id="asdf"> 
    <div id="mUpload"> 
    <input type="file" id="element_input" class="upload" name="fileX[]" /> 
    <input type="submit" value="Upload" /> 
    </div> 
</form> 

PHP 코드


$target = "upload/"; 
$target = $target . $_FILES['fileX']['name']; 
$ok=1; 

if(move_uploaded_file($_FILES['fileX']['tmp_name'], $target)) { 
    echo "The file " . $_FILES['fileX']['name'] . " has been uploaded"; 
    } 
else { 
    echo "There was a problem uploading" . $_FILES['fileX']['name'] . ". Sorry"; 
    } 
+0

무엇이 당신의 질문입니까? 작동하지 않는 것은 무엇입니까? –

+0

스크립트가 파일을 업로드하는 방법. 지금은 그렇지 않으며 오류가 없습니다. – PHPNooblet

답변

1

$_FILES 배열은 실제로는 다음과 같습니다

foreach($_FILES['fileX']['name'] as $index => $name) { 
    if(empty($name)) continue; 

    $target = "upload/"; 
    $target = $target . $name; 
    $ok=1; 

    if(move_uploaded_file($_FILES['fileX']['tmp_name'][$index], $target)) 
    { 
     echo "The file " . $name . " has been uploaded"; 
    } 
    else 
    { 
     echo "There was a problem uploading" . $name . ". Sorry"; 
    } 
} 

을 그리고 당신은 더 나은 코드를 들여 배워야한다 :

array (
    'fileX' => 
    array (
    'name' => 
    array (
     0 => '', 
     1 => 'Temp1.jpg', 
     2 => 'Temp2.jpg', 
    ), 
    'type' => 
    array (
     0 => '', 
     1 => 'image/jpeg', 
     2 => 'image/jpeg', 
    ), 
    'tmp_name' => 
    array (
     0 => '', 
     1 => '/tmp/php52.tmp', 
     2 => '/tmp/php53.tmp', 
    ), 
    'error' => 
    array (
     0 => 4, 
     1 => 0, 
     2 => 0, 
    ), 
    'size' => 
    array (
     0 => 0, 
     1 => 83794, 
     2 => 105542, 
    ), 
), 
) 

코드를 더욱 같이해야 의미!

+0

지금 시도해 볼게요. 감사합니다 – PHPNooblet

+1

그것은 일했다! 다시 한번 감사드립니다. – PHPNooblet