1. Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Folder Backup script ( 90% finished )

Discussion in 'Programming & Webmastering' started by Jelle Mees, Aug 30, 2008.

  1. Jelle Mees

    Jelle Mees New Member

    Joined:
    Jan 24, 2008
    Messages:
    718 (0.29/day)
    Thanks Received:
    126
    Location:
    Belgium ⇒ Limburg
    I am working on a backup script. It works pretty simpel.

    You place Backup.php in the folder you want to backup.
    You run Backup.php in your webbrowser.
    The script starts zipping all the content of the folder and then a download-popup will allow you to download the entire folder-content in a .zip file.

    The following code generates the text you see in your browser and starts the download once the backup is completed:

    Code:
    foreach ($filenames as $filename) {
        echo "Adding " . $filename . "<br/>";
        $zip->addFile($filename,$filename);
    }
    
    echo "Files: " . $zip->numFiles . "\n";
    echo "Status:" . $zip->status . "\n";
    $zip->close();
    echo "<meta http-equiv='refresh' content='0;url=Backup.zip'>";
    This is what happens at this time:
    - Text gets generated
    - Page scrolls down to bottem
    - Download begins

    This is what I want to happen:
    - Text gets generated
    - Page scrolls down automaticly while text is being generated
    - Download begins

    The person who helps me will be mentioned in the credits and offcourse I will share the script with you guys once it has all the features I want it to have.

    I am currently trying to do it with javascript...
     
    Last edited: Aug 30, 2008
  2. Oliver_FF

    Oliver_FF New Member

    Joined:
    Oct 15, 2006
    Messages:
    546 (0.19/day)
    Thanks Received:
    65
    Sadly PHP only generates static content, you can't get it to spew out data as it is processed - You create your http request, send it to the web server, the web server starts the php, when the php finishes executing the resulting html is sent back to the client.

    Sadly again you can't do this with javascript because it's a client side technology and the security restrictions aren't going to allow it.

    You could look into writing a JSP/Servlet and spawn off a new thread that does all the work, then have a html page with some ajax to query how much has been completed... But that's a LOT of effort :(
     
  3. DanTheBanjoman Señor Moderator

    Joined:
    May 20, 2004
    Messages:
    10,553 (2.77/day)
    Thanks Received:
    1,383
    Use exec() to start winzip/tar or whatever is available on the server and then put the target file as downloadlink? Put date/time in the name and it'll remain unique.
     
  4. Hayder_Master

    Hayder_Master

    Joined:
    Apr 21, 2008
    Messages:
    5,177 (2.18/day)
    Thanks Received:
    638
    Location:
    IRAQ-Baghdad
    Last edited: Aug 31, 2008
  5. Jelle Mees

    Jelle Mees New Member

    Joined:
    Jan 24, 2008
    Messages:
    718 (0.29/day)
    Thanks Received:
    126
    Location:
    Belgium ⇒ Limburg
    I find a way around it. What I wanted was for the user to view something animated while waiting for the backup, scrolling the generated text was the first thing that comes to mind. But since that requires quite a lot of code with AJAX, I decided to display a "loading..." animated gif untill the backup is complete. Once complete I scroll down with one line of javascript code.

    I am still having one issue. I am trying to add the code to a PHP-Fusion panel:

    Code:
    // GUI
    if(iSUPERADMIN) {
    	openside($p_data['panel_name']);
    
    	echo "<div style='text-align:center;'>";
    	if(empty($err_txt)) {
    		echo $locale['aw_last'] . "<br />"
    			. showdate("shortdate", filemtime(A_TOUCH_FILE));
    		if(iSUPERADMIN) {
    			echo "<p><a href='".FUSION_SELF."?force_backup=1'>"
    				.$locale['AWAU010']."</a>\n";
    			echo "<p><a href='".BASEDIR."Backup.php""'>"
    				.$locale['aw_download']."</a>\n";
    		}
    	} else {
    		echo $err_txt;
    	}
    	echo "</div>";
    
    	closeside();
    }
    //
    I get:

     
  6. W1zzard

    W1zzard Administrator Staff Member

    Joined:
    May 14, 2004
    Messages:
    14,962 (3.92/day)
    Thanks Received:
    11,769
    actually, not exactly. as soon as php sends output it goes to the browser which can display it as it receives it (with several limitations like html tables etc). what you describe is only happening when output buffering ( ob_start() ) is active.
     
  7. Jelle Mees

    Jelle Mees New Member

    Joined:
    Jan 24, 2008
    Messages:
    718 (0.29/day)
    Thanks Received:
    126
    Location:
    Belgium ⇒ Limburg
    Fixed the errorcode, stupid mistake lol.

    W1zzard, are you saying that what I asked in first post is possible?
     
  8. Oliver_FF

    Oliver_FF New Member

    Joined:
    Oct 15, 2006
    Messages:
    546 (0.19/day)
    Thanks Received:
    65
    Oh cool, i didn't know that :laugh:

    So if you could disable the output buffer or somehow flush the output buffer then the data in the buffer would go out in a http response packet which could be displayed by the client whilst the processing is still going on?
     

Currently Active Users Viewing This Thread: 1 (0 members and 1 guest)

Share This Page