Hi!
Sorry for my bad english.
I have this code:

<html>
<style type="text/css">
#traka{
border:1px solid black;
position:relative;
width:300px;
}
#boja{
position:absolute;
top:0;
left:0;
height:100%;
background-color:yellow;
}
#tekst{
text-align:center;
position:relative;
}
</style>
<script type="text/javascript">
wid=0;
function kreni(){
setTimeout("izvod()",700);
}
function izvod(){
wid+=10;
pos=(wid*100/300);
pos=Math.round(pos);
pos+="%";
document.getElementById('tekst').innerHTML=pos;
document.getElementById('boja').style.width=wid;
if(pos!="100%"){
kreni();
}}
</script>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data" onsubmit="kreni()">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
<div id='traka'><div id='boja'></div><div id='tekst'>0%</div></div>
</body>
</html>

How to make progress bar? (I know how, but I don't know how to check file size)
I think that this must be created with "iframe", but I don't know how.
And file "upload.php", what must be the content of this file?
Thanks!

Recommended Answers

All 11 Replies

You cannot get a progressbar directly from PHP. You need another language such as Perl or Flash. Digitarald has a really nice ajax upload script which you can use. It supports both single file and multifile uploads with progressbars.

Access it here : http://digitarald.de/project/fancyupload/

Let me know if you need any help with the documentation.

ofc you can make upload progress bar in php

How is this possible!
Forget all what I say.
What I want is this:
one page that has form for upload
When someone click on the button, it uploads this file and every second check the file size (check file size while uploading).
Then in one "<div>" element prints the size of the uploaded part of file (how many bit,byte,mb... is uploaded shown in percentage).

you can definitly use ajax just google and you will get tons of examples)

with php, well, there's an API for it in APC, and there's also the uploadprogress extension in PECL. Nothing built-in, though.

Yes, I already search. As you said I got many, many examples.
But I don't understand them. So, can you write simple code for do this.
Thanks!
I have this:

<script type="text/javascript">
function start(){
setTimeout("checkAndWrite()",1000);
}
function checkAndWrite(){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}else{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4 && xmlhttp.status==200){
uploadedPartOfFile=xmlhttp.responseText;
}
}
xmlhttp.open("GET",uploadedPart.php,true);
xmlhttp.send();
//
some code, can you write it
//
document.getElementById('uploadedPart').innerHTML=percent+"%";
if(percent==100){
document.getElementById('uploadedPart').innerHTML="File is uploaded!"
}else{
start();
}}
</script>
<form action="" method="post" onsubmit="start();">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
<div id="uploadedPart"></div>

What I must add in <form> tag?

Why dont you try perl, ;)

Because I know programing only in javascript (ajax) and php.

Please refer the link in my previous post. I have been searching for a way to do a progress bar in PHP for quite some time now and fancyupload is the easiest way to do it. You can upload several files at the same time in a multiupload fashion or a single file. I am pretty sure this is what you are looking for.

Yes, I saw it (and I saw many codes, but I don't understand them). I don't understand this code. I want to write this script (I don't know how to say, " I want to write script alone/myself"), not copy and paste. Is there, on this site, explanation that explain in detail the code that is used?

I think that you didn't understand me.
I don't want to make progres bar in php.
This is what I want:
With javascript (setTimeout("somefunction()",1000)) set repetition of somefunction() every second.
In this function ("somefunction()") should be "ajax", ie the program that will checking every second how much bytes uploaded is. "Ajax opens and sends" the information to a php file. Php file prints how many bytes uploaded is. The "ajax" get this number and show him on the page.
SIMPLE, SIMPLE and not COMPLEX
That's all!

If you are really intent on delveloping the progress bar for an upload in PHP, I beleive PHP 5.2 has the capability. For this there is a tutorial at http://www.ibm.com/developerworks/library/os-php-v525/index.html.

It needs a php_apc.dll to be activated on your server for it to work so I was unable to try it out since the service provider that I use does not have it active.

If you are able to get it to work, please do let me know.

Thank you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.