1

我目前正在为上传视频脚本制作一个上传进度条。因此,当我action="[var.path_to_upload_script]"在表单块中时,我的视频上传工作良好。

所以让我先粘贴我正在处理的所有代码。

这是表单代码:

            <div>
            <form name="form_upload" id="form_upload" method="post" enctype="multipart/form-data"  action="[var.path_to_upload_script]" style="margin: 0px; padding: 0px;">
            <input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>
              <noscript><input type="hidden" name="no_script" value="1" /></noscript>
              <input type="hidden" name="title" value="[var.title]" />
        <input type="hidden" name="description" value="[var.description]" />
        <input type="hidden" name="tags" value="[var.tags]" />
        <input type="hidden" name="location_recorded" value="[var.location_recorded]" />
        <input type="hidden" name="allow_comments" value="[var.allow_comments]" />
        <input type="hidden" name="allow_embedding" value="[var.allow_embedding]" />
        <input type="hidden" name="public_private" value="[var.public_private]" />
        <input type="hidden" name="channel" value="[var.channel]" />
        <input type="hidden" name="channel_name" value="[var.channel_name]" />
        <input type="hidden" name="sub_cat" value="[var.sub_cat]" />
        <input type="hidden" name="form_submitted" value="yes" />

        <div id="upload_slots"><span class="font5_16"><b>[var.lang_please_upload]</b></span><input type="file" name="upfile_0" size="71" value="" /></div>
<br />
<iframe id="upload_frame" name="upload_frame" frameborder="0" border="0" src="" scrolling="no" scrollbar="no" > </iframe>
<br />
        <noscript><br><input type="reset" name="no_script_reset" value="Reset" />&nbsp;&nbsp;&nbsp;<input type="submit" name="no_script_submit" value="Upload" /></noscript>
        </form>
                    <script language="javascript" type="text/javascript">
            <!--
            document.writeln('<input type="button" name="reset_button" value="Reset" onClick="resetForm();">&nbsp;&nbsp;&nbsp;<input type="button" id="submit" name="submit" value="Upload" onClick="uploadFiles();">');
            //-->
            </script>
        </div>

这里重要的是在表单块中具有操作,action="[var.path_to_upload_script]"否则文件的上传将无法正常工作。

这是进度条的 JAVASCRIPT 代码:

    $('#upload_frame').show();
    function set () {
        $('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');
    }
    setTimeout(set);

以及来自 upload_frame.php 的代码

<?php

$url = basename($_SERVER['SCRIPT_FILENAME']);

//Get file upload progress information.
if(isset($_GET['progress_key'])) {
    $status = apc_fetch('upload_'.$_GET['progress_key']);
    echo $status['current']/$status['total']*100;
    die;
}
//

?>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.js" type="text/javascript"></script>
<link href="style_progress.css" rel="stylesheet" type="text/css" />

<script>
$(document).ready(function() { 
//

    setInterval(function() 
        {
    $.get("<?php echo $url; ?>?progress_key=<?php echo $_GET['up_id']; ?>&randval="+ Math.random(), { 
        //get request to the current URL (upload_frame.php) which calls the code at the top of the page.  It checks the file's progress based on the file id "progress_key=" and returns the value with the function below:
    },
        function(data)  //return information back from jQuery's get request
            {
                $('#progress_container').fadeIn(100);   //fade in progress bar  
                $('#progress_bar').width(data +"%");    //set width of progress bar based on the $status value (set at the top of this page)
                $('#progress_completed').html(parseInt(data) +"%"); //display the % completed within the progress bar
            }
        )},500);    //Interval is set at 500 milliseconds (the progress bar will refresh every .5 seconds)

});


</script>

<body style="margin:0px">
<!--Progress bar divs-->
<div id="progress_container">
    <div id="progress_bar">
         <div id="progress_completed"></div>
    </div>
</div>
<!---->
</body>

现在,如果我[var.path_to_upload_script]从表单块中的操作中删除,进度条工作正常,但文件上传脚本失败。

所以我想问一下如何使进度条action="[var.path_to_upload_script]"在表单标签中使用?

提前致谢!

4

1 回答 1

0

您正在使用 php 代码设置属性,但它看起来像是某种模板:

$('#upload_frame').attr('src','upload_frame.php?up_id=<?php echo $up_id; ?>');

尝试更改为

$('#upload_frame').attr('src','upload_frame.php?up_id=[var.up_id]');

同样的问题可能在这里:<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo $up_id; ?>"/>

于 2013-10-18T18:47:23.650 回答