Hello ,

Intro (don't have to read it 😃 ) :
This is my first post over here , I can't call my self a coder of course I just write simple php lines form time to time to do what I need to be done and I'm happy to be in such an amazing community like this 🙂

The problem (Please read it 🙂 ) :
I made a very simple script to remote upload files to my webserver
it consist of 2 files : "index.html" & "download.php"

Here is the code of both of them :

index.html :

<html>
	<head>
		<title>Remote Upload Page</title>

<script>
function submitonce(theform){
//if IE 4+ or NS 6+
if (document.all||document.getElementById){
//screen thru every element in the form, and hunt down "submit" and "reset"
for (i=0;i<theform.length;i++){
var tempobj=theform.elements[i]
if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset")
//disable em
tempobj.disabled=true
}
}
}
        </script>
	</head>

<body>

<form method=post action="download.php" onSubmit="submitonce(this)">

<p align="center"><b><font face="Tahoma">Enter Download URL :</font></b></p>
<p align="center"> <input type="text" name="Link" size="50" dir="ltr">&nbsp;
<input type="submit" name="submit" value="Upload" dir="ltr"> </p>
</body>

</html>

The java script is just to disable the upload button after clicking on it .

download.php :

<?php
define('BUFSIZ', 4095);
$url = $Link;
$dir = 'files/';
$rfile = fopen($url, 'r');
$lfile = fopen($dir . basename($url), 'w');
while(!feof($rfile))
fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);
fclose($rfile);
fclose($lfile);
echo '<p align="center"><b><font face="Tahoma" size="5" color="#339933">File Remote Download Complete !</font></b></p>';
?>

of course no need to explain what I did as you know more than I do !

the problem now :
When I enter a large file URL the page loads for long time and it some times lag my browser , and in the end any way the file don't download if it's big (like more than 100Mb)
so I need to add a progress bar like the one I see on the file uploading websites so that the page don't load for ever
just the progress go from zero to 100 or some thing then echo that the download is complete .

Any info would be helpful and please try to give as much details as possible coz I'm almost a newbie :o

Regards,
Masry

    It is not easily done. In pure php it is even impossible. Search this forum or google for "php upload progress bar" to find how to go over this.

      Hello wilku ,

      Thanks for your reply , I already did a search but I guess the idea is diffrent a little bit as I'm not uploading
      I'm just sending a URL and the server download it from another server , so there is no actual upload from the end user at all .

      if you know how even to show a word : Loading......
      till the upload is complete then it echo : download is complete .

        20 days later

        wow I didn't expect that I wont get replies like that
        I thought this is a piece of cake for you guys !!

          The main problem is that PHP is running on the server, so it cannot dynamically turn things on and off in your browser such as a client-side application like JavaScript or Flash.

          What you could do is a combination of JavaScript and PHP referred to as "AJAX" (a search on "PHP AJAX" should give you a gazillion or so hits 🙂 ). You would have JavaScript on the page (1) display a "loading" graphic or whatever you want, (2) send the request via an "AJAX" XMLHttpRequest object, (3) when the JavaScript AJAX function detects a response from your server-side script it would remove the "loading" image and display the output.

            Not that I've ever thought about a downloading progress bar.... browsers tend to already have such things ... I wonder if it's possible for the Ajax-driven downloader to get the headers of the download as it starts and extract the Content-Length header from it. Then use that somehow during the download. Also necessary would be to query the XMLHTTPRequest object on a regular basis to see how much it has downloaded (I don't know offhand if the object provides this information. I know Firefox extensions can do it, but the JavaScript running them has privileges that code in pages doesn't.)

              10 months later

              I know this is an old thread but...
              I use this on an upload script I made.

              Put this in the head

              <script type="text/javascript">
              function showIcon() {
              window.setTimeout('showProgress()', 0);
              }
              function showProgress() {
              document.getElementById('progressImg').style.display = 'inline';
              }
              </script>
              
              
              
              

              Alter your input string like this:

              <input type="submit" name="submit" onclick="showIcon();" value="Upload" dir="ltr"> </p>
              
              

              Then add a progress.gif or something similar.
              I've included one for you.

              <div class="progress" id="progressImg">&nbsp;
              <img src="progress.gif" alt="Uploading" />
              </div>
              
                Write a Reply...