# Folder Backup script ( 90% finished )



## JRMBelgium (Aug 30, 2008)

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:


```
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...


----------



## Oliver_FF (Aug 31, 2008)

Jelle Mees said:


> 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.
> ...



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


----------



## Deleted member 3 (Aug 31, 2008)

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.


----------



## Hayder_Master (Aug 31, 2008)

wow . im still shot , nice work

so see this link im think this useful for complete your work

http://www.hotscripts.com/PHP/Scripts_and_Programs/File_Manipulation/File_Backup/index.html


----------



## JRMBelgium (Aug 31, 2008)

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:


```
// 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:



> Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /home/pcgidsin/public_html/Websites/TNAC/infusions/auto_db_backup_panel/auto_db_backup_panel.php on line 204


----------



## W1zzard (Aug 31, 2008)

Oliver_FF said:


> 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.



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.


----------



## JRMBelgium (Aug 31, 2008)

Fixed the errorcode, stupid mistake lol.

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


----------



## Oliver_FF (Aug 31, 2008)

W1zzard said:


> 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.



Oh cool, i didn't know that 

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?


----------

