FlyingIsFun1217 Posted June 28, 2008 Share Posted June 28, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/ Share on other sites More sharing options...
.josh Posted June 28, 2008 Share Posted June 28, 2008 I see at least 4 places where you forgot a ; at the end of your line Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576967 Share on other sites More sharing options...
thatsgreat2345 Posted June 28, 2008 Share Posted June 28, 2008 $fileContents .= '</user>' fwrite($postsXML, $fileContents) fclose($postsXML) Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576971 Share on other sites More sharing options...
MasterACE14 Posted June 28, 2008 Share Posted June 28, 2008 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576977 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 28, 2008 Author Share Posted June 28, 2008 Ahh, jeeze, I missed those. I've been using a container-completion plugin on my text editor, sometimes ends like you've seen. FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576983 Share on other sites More sharing options...
MasterACE14 Posted June 28, 2008 Share Posted June 28, 2008 topic solved ? Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-576984 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 29, 2008 Author Share Posted June 29, 2008 Not quite... there are still problems; just one's I can't address right now. FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-577057 Share on other sites More sharing options...
thatsgreat2345 Posted June 29, 2008 Share Posted June 29, 2008 Maybe post your errors? Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-577059 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 29, 2008 Author Share Posted June 29, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-577476 Share on other sites More sharing options...
wildteen88 Posted June 29, 2008 Share Posted June 29, 2008 All the above errors are caused by the first error. You'll need to sort the first error in order for the rest to be resolved. Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-577501 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 30, 2008 Author Share Posted June 30, 2008 Now that I think of it, it really SHOULD have permissions, since I'm starting Apache, PHP, etc. as root (unix), so it should DEFINITELY have permissions. Is there something I'm missing? Tanner Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-578220 Share on other sites More sharing options...
.josh Posted June 30, 2008 Share Posted June 30, 2008 are the permissions on the file set right? Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-578222 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 30, 2008 Author Share Posted June 30, 2008 Should be. I'll just try it in Windows and see what I get. Imagine that, continuous root permissions in Windows are good for once! FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-578405 Share on other sites More sharing options...
FlyingIsFun1217 Posted June 30, 2008 Author Share Posted June 30, 2008 Alright, in Windows, I only get one error: Fatal error: Call to a member function add_file() on a non-object in C:\Path\createBackup.php on line 70 FlyingIsFun1217 Quote Link to comment https://forums.phpfreaks.com/topic/112381-code-isnt-correct/#findComment-578409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.