pcw Posted March 26, 2009 Share Posted March 26, 2009 Hi, I am using bigdump to restore mysql databases. I have shortened the script down quite a lot. I have this script which allows me to select the database to backup, from a drop down menu. <?php $backupFileDir = "backup/"; $handle = opendir($backupFileDir); while ($sqlfile = readdir($handle)) { $sqlfiles[] = $sqlfile; } closedir($handle); sort($sqlfiles); print "<form action='bigdump.php?' method='POST'>"; print "<select name='sqlfile'>"; print "<option>Choose Database Backup</option>"; foreach ($sqlfiles as $sqlfile) { if (($sqlfile != ".") And ($sqlfile != "..")) { print sprintf("<option value='$backupFile%s'>%s</option>", $sqlfile, $sqlfile); } } print "</select>"; print "<input type='submit' name='submit' value='submit'>"; print "</form>"; print "</center>"; print ' </td> </tr> </table>'; ?> I then pass sqlfile to the bigdump.php script. I have this: <?php $filename = $_POST['sqlfile']; if (!$error && !isset ($_REQUEST["fn"]) && $filename!="") { echo ("<p><a href=\"".$_SERVER["PHP_SELF"]."?start=1&fn=".urlencode($filename)."&foffset=0&totalqueries=0\">Are you sure you would like to restore this database?</a></p>\n"); } But when I submit the form, and then click the link to confirm the restoration, I get this error: Can't open mysql_moveitho_sitebuilder_22_Mar_2009_time_18_41_26.sql.gz for import Please, check that your dump file name contains only alphanumerical characters, and rename it accordingly, for example: mysql_moveitho_sitebuilder_22_Mar_2009_time_18_41_26.sql.gz. Or, specify $filename in bigdump.php with the full filename. I have printed $filename in bigdump.php and it prints the whole filename, so i think the problem is something to do with $filename not being assigned the full filename, but a $_POST How can I fix this? Thanks Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/ Share on other sites More sharing options...
WolfRage Posted March 26, 2009 Share Posted March 26, 2009 Unzip the file. it needs to be a .sql file not .gz ... Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794591 Share on other sites More sharing options...
pcw Posted March 26, 2009 Author Share Posted March 26, 2009 Hi WolfRage, thanks for your reply. If I assign the variable $filename like this: $filename = 'mysql_moveitho_sitebuilder_22_Mar_2009_time_18_41_26.sql.gz'; Then it works. If I assign $filename like this $filename = $_POST['sqlfile']; it doesnt work. I am not certain that this error is because the file is not unzipped, as it works fine the first way Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794592 Share on other sites More sharing options...
WolfRage Posted March 26, 2009 Share Posted March 26, 2009 Try echoing $_POST['sqlfile'] make sure that it is exactly what it is susposed to be, I see extra characters in your script and I am guessing that it will not be what you expect. Remember always double check your input with an echo, if it is not doing what you expect then it is probably not what you think it is. Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794596 Share on other sites More sharing options...
pcw Posted March 26, 2009 Author Share Posted March 26, 2009 Hi WolfRage, echo $_POST['sqlfile']; gave me mysql_moveitho_sitebuilder_22_Mar_2009_time_18_41_26.sql.gz which is the correct name of the file. I cannot understand why this wont work when assigned to $filename Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794601 Share on other sites More sharing options...
WolfRage Posted March 26, 2009 Share Posted March 26, 2009 Is that file in the same directory as the big_dump script? Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794604 Share on other sites More sharing options...
pcw Posted March 26, 2009 Author Share Posted March 26, 2009 Nope it is in another folder called backup lol, I overlooked that part. Now I have another prob: $filename = "backup/$_POST['sqlfile']"; I get this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/moveitho/public_html/sitebuilder/bigdump.php on line 12 How can I assign a directory and the posted file to $filename? Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794614 Share on other sites More sharing options...
WolfRage Posted March 26, 2009 Share Posted March 26, 2009 <?php $filename = 'backup/'.$_POST['sqlfile']; ?> Link to comment https://forums.phpfreaks.com/topic/151263-solved-passing-variable-prob-with-bigdump/#findComment-794618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.