Jump to content

Code isn't correct?


FlyingIsFun1217

Recommended Posts

Hey!

 

I've taken the liberty of looking up example source as to how to write to a zip file, and I think I've got everything I need set up, but I get an error. Here's the source:

 

<?php
include('createZip.php');
include('connectInfo.php');
include('createConnection.php');

$users = $_POST['usersBackup'];
$posts = $_POST['postsBackup'];

$fileContents = '';

$queryPosts = mysql_query('SELECT time, title, content, author, number FROM posts ORDER BY number DESC');
$queryUsers = mysql_query('SELECT user, passmd5, permissions, number FROM users ORDER BY number DESC');

if($users = 'on')
{
	$fileContents .= '<users>';
	while($data = mysql_fetch_array($queryUsers, MYSQL_ASSOC))
	{
		$fileContents .= '<user>';

			$fileContents .= '<user>'.$data['user'].'</user>';
			$fileContents .= '<passmd5>'.$data['passmd5'].'</passmd5>';
			$fileContents .= '<permissions>'.$data['permissions'].'</permissions>';
			$fileContents .= '<number>'.$data['number'].'</number>';

		$fileContents .= '</user>'
	}
	$fileContents .= '</users>';

	$usersXML = fopen('users.xml', 'w');
	fwrite($usersXML, $fileContents);
	fclose($usersXML);
}

if($posts = 'on')
{
	$fileContents = '';
	$fileContents .= '<posts>';
	while($data = mysql_fetch_array($queryPosts, MYSQL_ASSOC))
	{
		$fileContents .= '<post>';

			$fileContents .= '<time>'.$data['time'].'</time>';
			$fileContents .= '<title>'.$data['title'].'</title>';
			$fileContents .= '<content>'.$data['content'].'</content>';
			$fileContents .= '<author>'.$data['author'].'</author>';
			$fileContents .= '<number>'.$data['number'].'</number>';

		$fileContents .= '</post>'
	}
	$fileContents .= '</posts>';		

	$postsXML = fopen('posts.xml', 'w');
	fwrite($postsXML, $fileContents)
	fclose($postsXML)
}

if($users == '' && $posts == '')
{
	echo '<script type="text/javascript">';
	echo 'window.location = "backup.php"';
	echo '</script>';
}

else
{
	$backupZIP = new zipfile();

	if($users == 'on')
	{
		$dataUsers = implode('', file('users.xml'));
		$backupZip -> add_file($dataUsers, 'users.xml');
	}

	if($posts == 'on')
	{
		$dataPosts = implode('', file('posts.xml'));
		$backupZip -> add_file($dataPosts, 'posts.xml');
	}

	header('Content-type: application/octet-stream');
	header('Content-disposition: attachment; filename=Backup.zip');
	echo $backupZip -> file();
}

include('closeConnection.php');
?>

 

Don't worry about the zip-writing stuff, that'll be my problem if/when it comes up. Right now I'm getting an error that "Parse error: syntax error, unexpected '}' in createBackup.php on line 27". Why though? It seems like there's no wrong syntax there.

 

FlyingIsFun1217

Link to comment
https://forums.phpfreaks.com/topic/112381-code-isnt-correct/
Share on other sites

<?php
include('createZip.php');
include('connectInfo.php');
include('createConnection.php');

$users = $_POST['usersBackup'];
$posts = $_POST['postsBackup'];

$fileContents = '';

$queryPosts = mysql_query('SELECT time, title, content, author, number FROM posts ORDER BY number DESC');
$queryUsers = mysql_query('SELECT user, passmd5, permissions, number FROM users ORDER BY number DESC');

if($users = 'on')
{
	$fileContents .= '<users>';
	while($data = mysql_fetch_array($queryUsers, MYSQL_ASSOC))
	{
		$fileContents .= '<user>';

			$fileContents .= '<user>'.$data['user'].'</user>';
			$fileContents .= '<passmd5>'.$data['passmd5'].'</passmd5>';
			$fileContents .= '<permissions>'.$data['permissions'].'</permissions>';
			$fileContents .= '<number>'.$data['number'].'</number>';

		$fileContents .= '</user>';
	}
	$fileContents .= '</users>';

	$usersXML = fopen('users.xml', 'w');
	fwrite($usersXML, $fileContents);
	fclose($usersXML);
}

if($posts = 'on')
{
	$fileContents = '';
	$fileContents .= '<posts>';
	while($data = mysql_fetch_array($queryPosts, MYSQL_ASSOC))
	{
		$fileContents .= '<post>';

			$fileContents .= '<time>'.$data['time'].'</time>';
			$fileContents .= '<title>'.$data['title'].'</title>';
			$fileContents .= '<content>'.$data['content'].'</content>';
			$fileContents .= '<author>'.$data['author'].'</author>';
			$fileContents .= '<number>'.$data['number'].'</number>';

		$fileContents .= '</post>';
	}
	$fileContents .= '</posts>';		

	$postsXML = fopen('posts.xml', 'w');
	fwrite($postsXML, $fileContents);
	fclose($postsXML);
}

if($users == '' && $posts == '')
{
	echo '<script type="text/javascript">';
	echo 'window.location = "backup.php"';
	echo '</script>';
}

else
{
	$backupZIP = new zipfile();

	if($users == 'on')
	{
		$dataUsers = implode('', file('users.xml'));
		$backupZip -> add_file($dataUsers, 'users.xml');
	}

	if($posts == 'on')
	{
		$dataPosts = implode('', file('posts.xml'));
		$backupZip -> add_file($dataPosts, 'posts.xml');
	}

	header('Content-type: application/octet-stream');
	header('Content-disposition: attachment; filename=Backup.zip');
	echo $backupZip -> file();
}

include('closeConnection.php');
?>

 

that should be right now.

 

ACE

Link to comment
https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576977
Share on other sites

just one's I can't address right now.

 

Warning: fopen(users.xml) [function.fopen]: failed to open stream: Permission denied in /opt/lampp/htdocs/blog/createBackup.php on line 30

 

Warning: fwrite(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/blog/createBackup.php on line 31

 

Warning: fclose(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/blog/createBackup.php on line 32

 

Warning: fopen(posts.xml) [function.fopen]: failed to open stream: Permission denied in /opt/lampp/htdocs/blog/createBackup.php on line 53

 

Warning: fwrite(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/blog/createBackup.php on line 54

 

Warning: fclose(): supplied argument is not a valid stream resource in /opt/lampp/htdocs/blog/createBackup.php on line 55

 

Warning: file(users.xml) [function.file]: failed to open stream: No such file or directory in /opt/lampp/htdocs/blog/createBackup.php on line 71

 

Warning: implode() [function.implode]: Invalid arguments passed in /opt/lampp/htdocs/blog/createBackup.php on line 71

 

Fatal error: Call to a member function add_file() on a non-object in /opt/lampp/htdocs/blog/createBackup.php on line 72

 

I know the permission denied errors (I'm running Lampp in a root directory), but the others...

 

FlyingIsFun1217

Link to comment
https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-577476
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.