2014-10-30 2 views
0

에 다시 포함하므로 업로드하는 동안 진행률 표시 줄을 보여주는 다중 업로드 가능성을 인터넷에서 검색했습니다. 저기에 많은 사람들이 있기 때문에 나는 내 필요에 맞는 것을 빨리 발견했다.PHP + jQuery Upload는 내 웹 사이트를

이제 업로드가 끝난 후 문제가 발생합니다. 업로드가 끝나자 마자 DIV에서 "파일 [번호] : 파일 이름 (크기)이 업로드되었습니다"상태가 업로드됩니다. 그러나 그것은 나에게 그 상태를 보여줄뿐만 아니라 내 웹 사이트 레이아웃을 복제본으로 다시 포함합니다.

누군가가 내가 하루 종일 거기에 앉아 및 오류 :(

이것은 HTML + 양식입니다 찾을 수 없습니다로이 나를 도울 수있는 사항 : jQuery를 파일이 필요

<div id="main"> 
<form id="pupload" action="upload.php" method="POST" enctype="multipart/form-data"> 
    <fieldset class="tabulated"> 
     <table id="down" class="bbcode_table" cellspacing="1"> 
      <thead> 
       <tr class="Cnorm"> 
        <td><input type="file" name="files[]" multiple="multiple" id="files"></td> 
       </tr> 
      </thead> 
      <tbody> 
       <tr class="Cmite"> 
        <td><input id="submit" class="button1" type="submit" value="Upload"></td> 
       </tr> 
      </tbody> 
     </table> 
    </fieldset> 
</form> 
<div class="progress"> 
     <div class="bar"></div> 
     <div class="percent">0%</div> 
</div> 
{msg} 
<div id="status"></div> 

<script> 
    jQuery(document).ready(function ($) { 
    "use strict"; 

var bar = $('.bar'); 
var percent = $('.percent'); 
var status = $('#status'); 

$('form').ajaxForm({ 
beforeSend: function() { 
    status.empty(); 
    var percentVal = '0%'; 
    bar.width(percentVal); 
    percent.html(percentVal); 
}, 
uploadProgress: function(event, position, total, percentComplete) { 
    var percentVal = percentComplete + '%'; 
    bar.width(percentVal); 
    percent.html(percentVal); 
}, 
success: function(data, statusText, xhr) { 
    var percentVal = '100%'; 
    bar.width(percentVal); 
    percent.html(percentVal); 
    status.html(xhr.responseText); 
}, 
error: function(xhr, statusText, err) { 
    status.html(err || statusText); 
} 
}); 

}); 
</script> 
</div> 

을 . 웹 사이트 헤더에서 호출되는

이것에 PHP 코드입니다 :

<?php 

defined ('main') or die ('no direct access'); 

$main_dir = 'include/downs/public-upload/'; 

// Upload dirs sorted by file types 
$files = $main_dir.'files/'; 
$images = $main_dir.'images/'; 
$media = $main_dir.'media/'; 
$video = $main_dir.'video/'; 

// File extensions 
$files_ext = array('apk','exe','doc','docx','docm','gadget','html','ini','pdf','php','rar','sh','txt','xlsx','zip'); 
$images_ext = array('gif','jpg','JPG','jpe','jpeg','JPEG','png','PNG'); 
$media_ext = array('mp3','ogg','wav'); 
$video_ext = array('avi','mp4','3gp'); 

$msg = ''; 
     // Check rights first to make sure we can put the file in the directory 
     if (!is_writeable ($main_dir)) { 
       $msg = 'The folder "include/downs/<b>public-upload</b>/" requires WRITE (chmod 777) permission!!! Please set the WRITE (chmod 777) permission and reload the page.'; 
     } 
     // Now we can upload our file 
     $tpl = new tpl ('admin/pupload/pupload_upload'); 
      if ($_SERVER['REQUEST_METHOD'] == 'POST' and isset($_FILES['files'])) 
      { 
       // loop all files 
       foreach ($_FILES['files']['name'] as $i => $name) 
       { 
        $pathinfo = pathinfo($name); 

        // if file not uploaded then skip it 
         if (!is_uploaded_file($_FILES['files']['tmp_name'][$i])) 
         continue; 

        // now we can move the uploaded files 
        // IMAGES 
        if (in_array($pathinfo['extension'], $images_ext)) { 

        if (move_uploaded_file($_FILES['files']['tmp_name'][$i], $images . $name)) 
        { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#00FF00">successfully uploaded</font><br />'; 
        } else { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#FF0000">not successfully uploaded</font><br />'; 
        } 
        // FILES 
        } else if (in_array($pathinfo['extension'], $files_ext)) { 

        if (move_uploaded_file($_FILES['files']['tmp_name'][$i], $files . $name)) 
        { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#00FF00">successfully uploaded</font><br />'; 
        } else { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#FF0000">not successfully uploaded</font><br />'; 
        } 
        // VIDEOS 
        } else if (in_array($pathinfo['extension'], $video_ext)) { 

        if (move_uploaded_file($_FILES['files']['tmp_name'][$i], $video . $name)) 
        { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#00FF00">successfully uploaded</font><br />'; 
        } else { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#FF0000">not successfully uploaded</font><br />'; 
        }     
        // MEDIA 
        } else if (in_array($pathinfo['extension'], $media_ext)) { 

        if (move_uploaded_file($_FILES['files']['tmp_name'][$i], $media . $name)) 
        { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#00FF00">successfully uploaded</font><br />'; 
        } else { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#FF0000">not successfully uploaded</font><br />'; 
        } 
        } else { 
         $msg .= '<b>File ' .($i+1). ':</b> ' . $name . '&nbsp; (' . niceBytes($_FILES['files']['size'][$i]) . ') <font color="#FF0000">has an unsupported ending</font><br />'; 
        } 
       } 
      } 
$tpl->set_ar_out(array('msg' => $msg), 0); 
?> 
,536,913,632 10

파일이 폴더에 저장 될 때 업로드가 작동하고 "업로드 성공"메시지가 표시되지만 "include()"기능을 실행하는 것처럼 웹 사이트 레이아웃이 다시 포함됩니다.

나는 이것에 얻을 수 있던 어떤 도움든지를 위해 중대하다. 이 문제에 대한

+0

어쩌면 $ ('status')를 지울 수 있습니까? status.html (""); –

+0

따라서 status.html() 앞에 status.empty()를 넣으면 성공할 수 있습니다 : function? 나는 그것을 시도했지만 불행히도 아무것도 바뀌지 않았다 : ( –

+0

아마도 xhr.responseText가 헤더를 반환하고있다.) upload.php에서 헤더를 확인한다. –

답변

0

솔루션은 2 일 수 :

1 만 당신이 필요로하는 데이터를 인쇄 대상 페이지 (upload.php로)을 수정합니다. 당신이

내가 먼저 upload.php에 변수 MSG의 에코을하고 1 옵션에 자신을 결정할 것입니다 원하는 데이터 만 표시하도록 아약스 기능 필터 "xhr.responseText"에서

2. 성공 아약스에서 "status.html (xhr.responseText)"가 여전히 전체 페이지를 검색하는 경우 "status.html (data)"를 시도 할 수 있습니다.

0

나는 오류를 발견했다고 생각합니다! 그것은 헤더 템플릿으로 이상한 일을하는 내 템플릿 시스템 인 것 같아요. 나는 그것을 고쳐야했지만 다시 그것을 가지고 놀았지만 그것을 되풀이해야만한다.) 힌트를 주셔서 감사합니다. ADASein

관련 문제