Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript PHP+;jQuery上传包括我的网站再次处于状态_Javascript_Php_Jquery_Html_Multi Upload - Fatal编程技术网

Javascript PHP+;jQuery上传包括我的网站再次处于状态

Javascript PHP+;jQuery上传包括我的网站再次处于状态,javascript,php,jquery,html,multi-upload,Javascript,Php,Jquery,Html,Multi Upload,所以我在互联网上搜索了一个多重上传的可能性,它在上传时会显示一个进度条。因为有很多,我很快找到了一个适合我需要的 现在我遇到了一个问题后,上传已经完成。上传完成后,它会在DIV中显示上传“文件[编号]:文件名(大小)已上传”的状态。但是,它不仅会显示状态,还会再次显示我的网站布局作为副本 请有人帮我解决这个问题,因为我坐了一整天都没发现错误:( 这是HTML+表单: <div id="main"> <form id="pupload" action="upload.php" m

所以我在互联网上搜索了一个多重上传的可能性,它在上传时会显示一个进度条。因为有很多,我很快找到了一个适合我需要的

现在我遇到了一个问题后,上传已经完成。上传完成后,它会在DIV中显示上传“文件[编号]:文件名(大小)已上传”的状态。但是,它不仅会显示状态,还会再次显示我的网站布局作为副本

请有人帮我解决这个问题,因为我坐了一整天都没发现错误:(

这是HTML+表单:

<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>

0%  
{msg}
jQuery(文档).ready(函数($){
“严格使用”;
var bar=$('.bar');
变量百分比=$('.percent');
变量状态=$(“#状态”);
$('form').ajaxForm({
beforeSend:function(){
status.empty();
var percentVal='0%';
条形宽度(百分比值);
html(percentVal);
},
上载进度:功能(事件、位置、总数、完成百分比){
var percentVal=percentComplete+“%”;
条形宽度(百分比值);
html(percentVal);
},
成功:函数(数据、状态文本、xhr){
var percentVal=‘100%’;
条形宽度(百分比值);
html(percentVal);
html(xhr.responseText);
},
错误:函数(xhr、statusText、err){
html(err | | statusText);
}
}); 
});
所需的jQuery文件正在网站标题中调用

这是它的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);
?>

当文件被放入文件夹时,上传工作正常,并显示消息“上传成功”,但它再次包含了我的网站布局,就好像我要运行“include()”函数一样


我非常感谢在这方面能得到的任何帮助。

这个问题的解决方案可能是2:

1-修改目标页面(upload.php)以仅打印所需的数据

2-在ajax函数中,过滤“xhr.responseText”以仅显示所需的数据


我会选择第一个选项,在upload.php中回显变量msg。然后在成功的ajax上,您可以尝试“status.html(data)”if“status.html(xhr.responseText)”仍然检索整个页面。

我想我找到了错误!似乎是我的模板系统在做一些奇怪的事情,因为页眉的事情让我调整了一些东西,然后它工作得很好。我已经修复了它,但在我再次玩它时不得不重新调整它;)感谢ADASein的提示。

可能正在清理$(“#状态”)之前status.html(“”);那么您的意思是在success:函数中将status.empty()放在status.html()前面?我尝试过,但不幸的是,它没有改变任何事情:(可能xhr.responseText也返回了标题。在upload.php中检查标题。Heya ADASein,再次感谢您的回复!这正是我所想的,但我看不出它返回任何标题的任何原因。upload.php据我所知或我所见,不创建任何标题。检查标题是什么意思?