Moin Jungs,
ich hab ein Problem mit dem PHP APC-Extension. Ich möchte einen Progressbar in mein Uploadformualar einbauen. Ich hab nur folgendes Problem. Die Funktion apc_fetch gibt erst Daten aus, wenn der Upload fertig ist.
Da mein Quellcode recht umfangreich ist, versuche ich nur die relevanten Passagen zu posten.
Das Forumalar wird mittels Smarty generiert:
|
PHP Quellcode
|
1
2
|
$smarty->assign('temp_upload_key', uniqid());
$smarty->display('upc.html');
|
progress.php
|
PHP Quellcode
|
1
2
3
4
5
6
|
<?php
$array = apc_fetch("upload_{$_GET['tid']}");
print_r($_GET);
print_r($array);
?>
|
process.php
|
PHP Quellcode
|
1
2
3
|
<?php
echo "upload finished!";
?>
|
upc.html
|
HTML Code
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
...
<script type="text/javascript">
var req = null;
function getXMLRequestHandle(){
try{
req = new XMLHttpRequest();
}catch (e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}catch (e){
try{
req = new ActiveXObject("Microsoft.XMLHTTP");
}catch (failed){
req = "failed";
}
}
}
}
function getProgress(){
if(req == "failed"){
alert("Fehler beim Erstellen eines XMLRequest. Deaktivieren Sie JavaScript, um diese Seite zu nutzen!");
return;
}
if(req == null)
getXMLRequestHandle();
req.onreadystatechange = function(){
switch(req.readyState){
case 4:
if(req.status == 200){
document.getElementById("debug").innerHTML = req.responseText;
}
break;
}
};
req.open("get", "progress.php?tid=" + document.getElementById("progress_key").value);
req.send(null);
}
function startUpload(){
window.setInterval("getProgress()", 2000);
}
...
<form action="process.php" target="hidden_upload" method="post" enctype="multipart/form-data">
...
<input type="hidden" name="submit" value="submit"/>
<p><input type="submit" value="upload!" onclick="this.disabled=true; startUpload();"/></p>
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="{$temp_upload_key}"/>
|