pcw Posted March 12, 2009 Share Posted March 12, 2009 Hi, I am having a bit of trouble with this script: <?php include("../../addons.php"); function edit_temp() { adminheader(); $directory = "../../templates/"; $handle = opendir($directory); while ($folder = readdir($handle)) { $folders[] = $folder; } closedir($handle); sort($folders); print "<form method='POST'>"; print "<select name='temp_folder'>"; Print "<option>Choose folder</option>"; foreach ($folders as $folder) { if (($folder != ".") And ($folder != "..")) { print sprintf("<option value='$directory/%s'>%s</option>", $folder, $folder); } } print "</select>"; print "<input type='submit' name='tmpupdate' value='update'>"; print "</form>"; #################### $tmp_folder = $_POST['temp_folder']; $con_fold = "$tmp_folder"; $handle1 = opendir($con_fold); while ($file = readdir($handle1)) { $files[] = $file; } closedir($handle1); sort($files); #################### print "<form method='POST'>"; print "<select name='temp_name'>"; Print "<option>Choose template</option>"; foreach ($files as $file) { if (($file != ".") And ($file != "..")) { print sprintf("<option value='$con_fold/%s'>%s</option>", $file, $file); } } print "</select>"; print "<input type='submit' name='tmpsubmit' value='submit'>"; print "</form>"; ####################### $filename = $_POST['file']; $fp = fopen( $filename, "r" ) or die("Couldn't open $filename"); while ( ! feof( $fp ) ) { $line .= fgets( $fp, 1024 ); } ############################ print <<<TEMPEDIT <form action="../../admin.php?cmd=modtmp" method="POST"> <table> <tr> <td colspan=2><textarea name="template" cols="90%" rows=25>$line</textarea></td> </tr> </table> <center><input type="submit" name="submit" value="submit"></center> </form> TEMPEDIT; adminfooter(); } edit_temp(); ?> When I first run the script, I get these errors: Warning: readdir(): supplied argument is not a valid Directory resource in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 34 Warning: closedir(): supplied argument is not a valid Directory resource in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 38 Warning: sort() expects parameter 1 to be array, null given in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 39 When the first form field is submitted the errors disappear and the second select menu is populated. When I select a file from the next select menu, and submit it, I get: Warning: readdir(): supplied argument is not a valid Directory resource in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 34 Warning: closedir(): supplied argument is not a valid Directory resource in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 38 Warning: sort() expects parameter 1 to be array, null given in /home/moveitho/public_html/sitebuilder/templates/admin/edit_template.php on line 39 when really it should show a textarea with the field contents inside, anyone know how I can fix this? Thanks Link to comment https://forums.phpfreaks.com/topic/149183-modifying-files/ Share on other sites More sharing options...
djlee Posted March 12, 2009 Share Posted March 12, 2009 Weird... and theres no opendir error ? maybe try while(($file = readdir($handle1) !== false) im just shooting into the dark though since i cant find anything else in that part of the code that i think is "bad" apart from $tmp_folder = $_POST['temp_folder']; $con_fold = "$tmp_folder"; would it not be better to just assign the con_fold directly to the POSTed variable as ur doing nothing but duplicating the data in the variable (doubling the RAM space that data holds, not a lot but hey im all for optimisation lol) Link to comment https://forums.phpfreaks.com/topic/149183-modifying-files/#findComment-783404 Share on other sites More sharing options...
pcw Posted March 12, 2009 Author Share Posted March 12, 2009 Hi, thanks for your reply. I took your advice and assigned con_fold directly to the POSTed variable. I tried while($file = readdir($handle1) !== false) but this causes the dropdown menu not to populate. Also the textarea field is still not displayed on the page. If anyone knows how to fix this, it will be much appreciated Link to comment https://forums.phpfreaks.com/topic/149183-modifying-files/#findComment-783414 Share on other sites More sharing options...
pcw Posted March 13, 2009 Author Share Posted March 13, 2009 Anyone got any ideas on this? Thanks Link to comment https://forums.phpfreaks.com/topic/149183-modifying-files/#findComment-783651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.