Jump to content

herghost

Members
  • Posts

    699
  • Joined

  • Last visited

Everything posted by herghost

  1. Hi all I am using this function to list all files and folders within a directory function getFilesFromDir($dir) { $files = array(); if ($handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { if(is_dir($dir.'/'.$file)) { $dir2 = $dir.'/'.$file; $files[] = getFilesFromDir($dir2); } else { $files[] = $dir.'/'.$file; } } } closedir($handle); } return array_flat($files); } function array_flat($array) { foreach($array as $a) { if(is_array($a)) { $tmp = array_merge($tmp, array_flat($a)); } else { $tmp[] = $a; } } return $tmp; } When I call the function I give the dir as a variable, however if the dir I want is a sub-dir of a current dir then the list starts from the main dir Basically say my file test.html is contained here files/test/test.html, the input I need to give is files/test/. This would then output in the array ->files/test/test.html. What I would like the output to be is test/test.html. How do I edit my recursive function to start from the final folder in the input? Thanks
  2. Thanks PFMaBiSmAd I hadn't changed max-post size. All the best
  3. I have a wierd issue that I cant quite pin down. Here is my code if(isset($_GET['world']) && ($_GET['world'] == "upload")) { $foldername = $_POST['worldname']; $target = "worlduploads/"; $ok=1; $allowed_types = array("application/octet-stream","application/zip","application/x-zip"); $allowed_extensions = array("zip"); if ($_FILES['file']['size'] > 262144000) { $max_size = round(25600); echo "Your file is too large. Maximum file size is 250MB. <br>"; $ok=0; } if ($_FILES["file"]["error"] > 0) { echo "Error: " . $_FILES["file"]["error"] . "<br />"; $ok=0; } else { $path_parts = pathinfo(strtolower($_FILES["file"]["name"])); if(in_array($_FILES["file"]["type"],$allowed_types) && in_array($path_parts["extension"],$allowed_extensions)) { $filename = $_FILES["file"]["name"]; } else { echo "Type " . $_FILES["file"]["type"] . " with extension " . $path_parts["extension"] . " not allowed <br />"; $ok=0; } } if($ok == 1) { move_uploaded_file($_FILES["file"]["tmp_name"], $target . $filename); $file_location = $target . $filename; if(file_exists($file_location)) { mkdir('worlduploads/'.$foldername.''); //create local $dir = 'worlduploads/'.$foldername.'/'; $zip = zip_open($file_location); while($zip_entry = zip_read($zip)) { $entry = zip_entry_open($zip,$zip_entry); $filename = zip_entry_name($zip_entry); $target_dir = $dir.substr($filename,0,strrpos($filename,'/')); $filesize = zip_entry_filesize($zip_entry); if (is_dir($target_dir) || mkdir($target_dir)) { if ($filesize > 0) { $contents = zip_entry_read($zip_entry, $filesize); file_put_contents($dir.$filename,$contents); } } } } else { echo "There was a problem saving the file. <br />"; } } } The idea is, the user enters a file name and upload there zip file, once uploaded this then unzips to a specified directory. This works fine if all the files are contained within the root of the zip, however if I try to upload a zip that contains folders then I just get Error: 1 displayed. I removed the unzip function and this is happening with just the upload. I would have thought that php would just copy the zip byte by byte without investigating its structure? I have tested my unzip with zips that contain folders and it works fine, maintains structure and puts the files where it should, its just the upload error that is giving me problems! PHP.ini is also set to 250mb Thanks for any insights
  4. Thanks, ill adapt and test yours
  5. Thanks PFM! Array ( [uploadedfile] => Array ( [name] => 629.zip [type] => application/octet-stream [tmp_name] => C:\wamp\tmp\phpB10A.tmp [error] => 0 [size] => 837990 ) ) An Octet-stream? Never heard of them! EDIT --- An ahhhhh - moment php.ini - extension=php_fileinfo.dll EDIT 2 --- Still reads as octet-stream hmm, a bit more reading needed
  6. Ehm, Im not sure on that logic as it still fires the error? I think my logic is correct if is not or is not or is not then error yours would have to meet all 3 conditions? Edit! Actually, yours would be if file is not and is not and is not = error Either way should work unless im mistaken? However neither does
  7. Hi all I am having a problem with an error message firing all the time? if ((($_FILES["file"]["type"] != "application/zip")) || (($_FILES["file"]["type"] != "application/x-zip-compressed")) || (($_FILES["file"]["type"] != "application/x-zip"))) { header('Location: scontrol.php?alert=notzip'); } This is firing when I try uploading a zip, I have 2 questions, have I missed a MIME type (using Chrome) and is a Winrar ZIP different from a standard zip (its not a .rar file!) Thanks
  8. Thats exactly where I got to before I hit the problem Say I am just trying to echo each one with a line break? I cant work out what to call as it is numeric? Cheers Dave
  9. Hi all What I am trying to achieve is a for each loop for the following output Array ( [result] => success [source] => getDirectory [success] => Array ( [0] => /root/mc/world/data/ [1] => /root/mc/world/level.dat [2] => /root/mc/world/level.dat_old [3] => /root/mc/world/players/ [4] => /root/mc/world/players/herghost.dat [5] => /root/mc/world/region/ [6] => /root/mc/world/region/r.-1.0.mcr [7] => /root/mc/world/region/r.0.0.mcr [8] => /root/mc/world/session.lock [9] => /root/mc/world/uid.dat ) ) How would I go about saving each path from the [success] output? Basically I wish to loop through the array and delete the files. Many Thanks
  10. ^^^ That logic is wrong. $savepath is the result from a mysql_query() statement (a bool true/1 in this case.) You cannot put a result from one query into another mysql_query() statement. The mysql_query() statement expects an SQL query string. Thanks to both! Sorted out my logic (as litebearers post) Still showing the error but saving as well, that will do for now, until I put all my components together.
  11. Im sure this is simple, but I cannot see what my problem is! I am hitting an error on my insert query Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 I know the output of $user_id is 1, so my error is on $mysavepath $mysavepath = $folder.'/'.$worldname.'_'.date("dMjY"); echo $mysavepath; $savepath = mysql_query("INSERT INTO saves (user_id,savepath) VALUES ('$user_id','$mysavepath')"); echo '<br>'.$savepath; if(!mysql_query($savepath)) { die('<br>Error: ' . mysql_error()); } however it all echos out ok? 188ea678f0dcdc8252aeb15e3c910408/world_15Jan152012 1 Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1 Can anyone see the problem? Cheers Dave
  12. Strangely, this only effects my local wamp server, as soon as put live works as expected!
  13. I seem to be having a problem with the below script, on the 1st run it doesnt print the $variables, but on refresh these a being written to file once? if(isset($_GET['sprop']) && ($_GET['sprop'] == "update")) { //my connection stuff // // $playername = "userid"; $nether = $_POST["nether"]; $lname = $_POST["lname"]; $query = $_POST["query"]; $flight = $_POST["flight"]; $portdd = $_POST["port"]; $rcon = $_POST["rcon"]; $seed = $_POST["seed"]; $sip = $_POST["sip"]; $wlist = $_POST["wlist"]; $san = $_POST["san"]; $omode = $_POST["omode"]; $pvp = $_POST["pvp"]; $dif = $_POST["dif"]; $sname = $_POST["sname"]; $gmode = $_POST["mode"]; $pmax = $_POST["max"]; $sm = $_POST["sm"]; $view = $_POST["view"]; $motd = $_POST["motd"]; sleep(3); $sftp = new Net_SFTP($ftp_s); if (!$sftp->login($ftp_u, $ftp_p)) { exit('Login Failed'); } echo $sftp->pwd() . "\r\n"; $sftp->put ("/root/mc/server.properties", "allow-nether=$nether level-name=$lname enable-query=$query allow-flight=$flight server-port=$portdd enable-rcon=$rcon level-seed=$seed server-ip=$sip white-list=$wlist spawn-animals=$san online-mode=$omode pvp=$pvp difficulty=$dif server-name=$sname gamemode=$gmode max-players=$pmax spawn-monsters=$sm view-distance=$view motd=$motd"); } As you can see, I have try adding a sleep to give it time to catch up but something tells me the variables are not being set 1st time for some reason, can anyone shine any light on this?
  14. These are no longer coming from an array, they are the post variables from a form, should have put it in the 1st post really
  15. Hi all I am having some issues basically $sftp->put("server.properties", "allow-nether=".$nether." level-name=".$lname.""); is not printing the variables. $sftp is part of the phpseclib and the fuction is in the same format as fwrite(), I have tried and failed using fwrite as well! I can echo out the 1st variable correctly, but as soon as I add the second I just get allow-nether= level-name= The variables $nether and $lname exist and I have echo'd them to check. I guess this is a formatting problem, just cant work it out!
  16. PFMaBiSmAd - I love you Thanks mate, that really helped :-)
  17. #Minecraft server properties #Sat Jan 07 07:04:01 UTC 2012 allow-nether=true level-name=This Blows! enable-query=true allow-flight=false server-port=25565 enable-rcon=false level-seed= server-ip= white-list=false spawn-animals=true online-mode=true pvp=true difficulty=1 server-name=Unknown Server gamemode=0 max-players=20 spawn-monsters=true view-distance=10 motd=A Minecraft Server
  18. Hi all I am having massive problems comparing the out put of array, basically my end result is to choose a selected option on a drop down in a form. I am trying to compare the output of ['allow-nether'] which is either true or false in my file. Here is what I have tried //code to get file contents $file_handle = fopen("saves/server.properties", "rb"); $vars = array(); while (!feof($file_handle) ) { $line_of_text = fgets($file_handle); $parts = explode('=', $line_of_text); //if date not required if ( !isset($parts[1]) ) { continue; } $vars[$parts[0]] = $parts[1]; } <?php //allow nether =false in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> which outputs: 1 false 2 selected="selected" and if I set the file to allow-nether=true <?php //allow nether =true in file echo "1 " .$vars['allow-nether']; if ( $vars['allow-nether'] == true ) { echo '<br>2 selected="selected"';} if ( $vars['allow-nether'] == false ) { echo '<br>3 selected="selected"';} if ( $vars['allow-nether'] == "true" ) { echo '<br>4 selected="selected"';} if ( $vars['allow-nether'] == "false" ) { echo '<br>5 selected="selected"';} if ( $vars['allow-nether'] === true ) { echo '<br>6 selected="selected"';} if ( $vars['allow-nether'] === false ) { echo '<br>7 selected="selected"';} if ( $vars['allow-nether'] === "true" ) { echo '<br>8 selected="selected"';} if ( $vars['allow-nether'] === "false" ) { echo '<br>9 selected="selected"';} ?> Gives: 1 true 2 selected="selected" What am I doing wrong?
  19. Hi again Andy Thanks for all your help on this, I fail to understand why its not doing what its meant to I have run this with the original code and the updated code, so here goes: $vars[$parts[0]] = $parts[1]; Array ( [allow-nether] => true [level-name] => This Blows! [enable-query] => true [allow-flight] => false [server-port] => 25565 [enable-rcon] => false [level-seed] => [server-ip] => [white-list] => false [spawn-animals] => true [online-mode] => true [pvp] => true [difficulty] => 1 [server-name] => Unknown Server [gamemode] => 0 [max-players] => 20 [spawn-monsters] => true [view-distance] => 10 [motd] => A Minecraft Server ) $vars[$parts[0]] = str_replace('false', '', $parts[1]); Array ( [allow-nether] => true [level-name] => This Blows! [enable-query] => true [allow-flight] => [server-port] => 25565 [enable-rcon] => [level-seed] => [server-ip] => [white-list] => [spawn-animals] => true [online-mode] => true [pvp] => true [difficulty] => 1 [server-name] => Unknown Server [gamemode] => 0 [max-players] => 20 [spawn-monsters] => true [view-distance] => 10 [motd] => A Minecraft Server )
  20. I have noticed that if I do something like <?php $test = $vars['allow-nether']; ?> Then when I come to call $test, dreamweaver is automatically opening a [ like it expects a array?
  21. Still not working Im afraid //if date not required if ( !isset($parts[1]) ) { continue; } $vars[$parts[0]] = str_replace('false', '', $parts[1]); } fclose($file_handle); <option <?php if ( $vars['allow-nether'] ) echo 'selected="selected"'; ?> value="true" >True</option> <option <?php if ( !$vars['allow-nether'] ) echo 'selected="selected"';?> value="false" >False</option>
  22. Thanks Andy! Enjoy your journey out! If anyone else or Andy when he gets back can help me further would be grateful! I know have: <form class="clean"> <ol> <li> <fieldset> <legend>Server Properties</legend> <ol> <li style=""> <label for="nether">Allow Nether</label> <select id="nether" name="nether"> <option value="true" <?php if ($vars['allow-nether'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['allow-nether'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="lname">Level Name</label> <input type="text" id="lname" name="lname" value="<?php print $vars['level-name'];?>" /> <label for="query">Enable Query</label> <select id="query" name="query"> <option value="true" <?php if ($vars['allow-query'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['allow-query'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="flight">Allow Flight</label> <select id="flight" name="flight"> <option value="true" <?php if ($vars['allow-query'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['allow-query'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="port">Server Port</label> <input type="text" id="port" name="port" value="<?php echo $vars['server-port'];?>" /> <label for="rcon">Enable RCON</label> <select id="rcon" name="rcon"> <option value="true" <?php if ($vars['allow-rcon'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['allow-rcon'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="seed">Level Seed</label> <input type="text" id="seed" name="seed" value="<?php echo $vars['level-seed'];?>" /> <label for="sip">Server IP</label> <input type="text" id="sip" name="sip" value="<?php echo $vars['server-ip'];?>" /> <label for="wlist">Enable Whitelist</label> <select id="wlist" name="wlist"> <option value="true" <?php if ($vars['white-list'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['white-list'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="san">Spawn Animals</label> <select id="san" name="san"> <option value="true" <?php if ($vars['spawn-animals'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['spawn-animals'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="omode">Online Mode</label> <select id="omode" name="wlist"> <option value="true" <?php if ($vars['white-list'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['white-list'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="pvp">Player v Player</label> <select id="pvp" name="pvp"> <option value="true" <?php if ($vars['pvp'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['pvp'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="dif">Difficulty</label> <select id="dif" name="div"> <option value="0" <?php if ($vars['difficulty'] == "0"){echo 'selected="selected"';}?> >Peaceful</option> <option value="1" <?php if ($vars['difficulty'] == "1"){echo 'selected="selected"';}?> >Easy</option> <option value="2" <?php if ($vars['difficulty'] == "2"){echo 'selected="selected"';}?> >Normal</option> <option value="3" <?php if ($vars['difficulty'] == "3"){echo 'selected="selected"';}?> >Hard</option> </select> <label for="sname">Server Name</label> <input type="text" id="sname" name="sname" value="<?php echo $vars['server-name'];?>" /> <label for="mode">Game Mode</label> <select id="mode" name="mode"> <option value="0" <?php if ($vars['gamemode'] == "0"){echo 'selected="selected"';}?> >Survival</option> <option value="1" <?php if ($vars['gamemode'] == "1"){echo 'selected="selected"';}?> >Creative</option> </select> <label for="max">Max Players</label> <input type="text" id="max" name="max" value="<?php echo $vars['max-player'];?>" /> <label for="sm">Spawn Monsters</label> <select id="sm" name="sm"> <option value="true" <?php if ($vars['spawn-monsters'] == "true"){echo 'selected="selected"';}?> >True</option> <option value="false" <?php if ($vars['spawn-monsters'] == "false"){echo 'selected="selected"';}?>>False</option> </select> <label for="view">View Distance</label> <input type="text" id="view" name="view" value="<?php echo $vars['view-distance'];?>" /> <label for="motd">Public Name</label> <input type="text" id="motd" name="motdw" value="<?php echo $vars['motd'];?>" /> </li> </ol> </fieldset> </li> </ol> <p style="text-align:right;"> <input type="reset" value="CANCEL" /> <input type="submit" value="OK" /> </p> </form> The problem is, i cant seem to get the selected function working properly, all selects default to the last possible answer (last <select> option)
×
×
  • 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.