使用php APC处理上传进度条

时间:2013-10-18 20:23:53

标签: php apc progress

您好我正在尝试使用php APC制作上传进度条。

所以这是我的html表单:

<?php 
//get unique id
$up_id = uniqid(); 
?>
                <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>

以下是进度条的java代码:

    $('#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">
<div id="progress_container">
    <div id="progress_bar">
         <div id="progress_completed"></div>
    </div>
</div>
</body>

现在上传进度条仅在以下行中有效: <form name="form_upload" id="form_upload" method="post" enctype="multipart/form-data" action="[var.path_to_upload_script]" style="margin: 0px; padding: 0px;">

是这样的:

<form name="form_upload" id="form_upload" method="post" enctype="multipart/form-data" action="" style="margin: 0px; padding: 0px;">

当表单中的操作为空时,它运行良好。但是我怎么能让它不是空行动呢?

我的问题是 - 如何使其与action="[var.path_to_upload_script]"一起使用?

提前致谢!

0 个答案:

没有答案