jtown Posted May 10, 2008 Share Posted May 10, 2008 I'm a newbie and have a question. why do I get the error "Warning: rename($old,$new) [function.rename]:" It says there is no such directory I can put variable into the rename function right? $old and $new are variable using $_POST to get the info from a text field. Hope this makes sense Thanks J Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 10, 2008 Share Posted May 10, 2008 The error says it all, there is no such directory. Make sure u have correct directory names for both $old and $new. For us to help u better, post more code. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 10, 2008 Author Share Posted May 10, 2008 here is my code The directory name are coming from my form fields right? Thanks <? $old = $_POST['oldname']; $new = $_POST['newname']; rename('$old', '$new'); $dir = opendir("images"); while ($file = readdir($dir)) { echo "current filename: $file\n"; ?> <form action="<? echo($PHP_SELF)?>" > <input type="hidden" name="oldname" /> <input type="text" name="newname" size="30"/><br /> <input type="button" value="change file name"/><br /><br /> </form> <? } closedir($dir); ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 10, 2008 Share Posted May 10, 2008 Don't use single quotes around variables, otherwise they will NOT be parsed. Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 righto. this won't work: rename('$old', '$new'); should be rename($old, $new); // OR rename("$old", "$new"); Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 10, 2008 Share Posted May 10, 2008 Echoing variables inside quotes seems a common practice for newbies. Anyways, u can add the following line inside your while loop: if($file == '.' or $file == '..'){ continue; } so that u dont show . or .. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 11, 2008 Author Share Posted May 11, 2008 WOW That has nothing to do with my question Quote Link to comment Share on other sites More sharing options...
Fadion Posted May 11, 2008 Share Posted May 11, 2008 WOW That has nothing to do with my question About my post? The code i posted will get rid of the . and .. when reading the folder content. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 Thanks man, but why am I getting the following error Warning: rename(,) [function.rename]: No such file or directory in /home/mmaaaco/public_html/jfanning/mm2232midterm/question_1.php on line 14 here is my code I'm new at this shit and am having a hard time wrapping my head around it $imgold = "images/GSP_02.Jjpg"; $dir = opendir("images"); $old = $_POST['oldname']; $new = $_POST['newname']; rename("$old", "$new"); while ($file = readdir($dir)) { echo "current filename: $file\n"; ?> <form action="<? echo($PHP_SELF)?>" method="post"> <input type="hidden" name="oldname" /> <input type="text" name="newname" size="30"/><br /> <input type="submit" value="change file name"/><br /><br /> </form> <? } closedir($dir); Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted May 12, 2008 Share Posted May 12, 2008 Post all the code, and point out line 14. Also echo $old and $new and see if the post value is making it over. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 This is all the code it is just a midterm question for class line 14 is the line where the rename function is. $old and $new do not make it over Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 Put: print_r($_POST); on the top of your page and show us the output after submitting the form. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 same error but now it shows Array() at the top. What the hell am I missing. I know it is something simple Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 Is that the whole code? And let me see the form code. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 here is all the code print_r($_POST); $imgold = "images/GSP_02.Jjpg"; $dir = opendir("images"); $old = $_POST['oldname']; $new = $_POST['newname']; rename("$old", "$new"); while ($file = readdir($dir)) { if($file == '.' or $file == '..'){ continue; } echo "current filename: $file\n"; ?> <form action="<? echo($PHP_SELF)?>" method="post"> <input type="hidden" name="oldname" /> <input type="text" name="newname" size="30"/><br /> <input type="submit" value="change file name"/><br /><br /> </form> <? } closedir($dir); Thanks man Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 So you're displaying a NEW form (HTML-wise) for every file? Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 even if I echo out $old there is no result Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 <?php if (isset($_POST)) { $dir = opendir("images"); $old = $_POST['oldname']; $new = $_POST['newname']; rename("$old", "$new"); echo "$old renamed to $new. <br />"; } while ($file = readdir($dir)) { if($file == '.' or $file == '..'){ continue; } echo "current filename: $file\n"; ?> <form action="<? echo($PHP_SELF)?>" method="post"> <input type="hidden" name="oldname" /> <input type="text" name="newname" size="30"/> <input type="submit" value="change file name"/> </form> <? } closedir($dir); ?> Try that. Should work. Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 Why do I get the same error about the directory??? Warning: rename(,dgfdgf) [function.rename]: No such file or directory in /home/mmaaaco/public_html/jfanning/mm2232midterm/question_1.php on line 15 My images that I'm trying to rename are in my images folder. line 15 has my rename function Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 Ah, I see the issue. Here: <?php if (isset($_POST)) { $dir = opendir("images"); $old = $_POST['oldname']; $new = $_POST['newname']; rename("$old", "$new"); echo "$old renamed to $new. <br />"; } while ($file = readdir($dir)) { if($file == '.' or $file == '..'){ continue; } echo "current filename: $file\n"; ?> <form action="<? echo($PHP_SELF)?>" method="post"> <input type="hidden" name="oldname" value="<?php echo $file ?>" /> <input type="text" name="newname" size="30"/> <input type="submit" value="change file name"/> </form> <? } closedir($dir); ?> Quote Link to comment Share on other sites More sharing options...
revraz Posted May 12, 2008 Share Posted May 12, 2008 If it's classwork, then maybe you should do most of the work with a little guidance, not having people actually do it for you. This is all the code it is just a midterm question for class Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 I didn't even see that line. @_@ But my code will work....(too late to take it back, lol). Quote Link to comment Share on other sites More sharing options...
jtown Posted May 12, 2008 Author Share Posted May 12, 2008 Still getting the same error Warning: rename(,) [function.rename]: No such file or directory in /home/mmaaaco/public_html/jfanning/mm2232midterm/question_1.php on line 15 What is going on with my rename function. Why does it say there is no directory? Thanks Quote Link to comment Share on other sites More sharing options...
DarkWater Posted May 12, 2008 Share Posted May 12, 2008 You aren't setting $oldname to anything. Quote Link to comment 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.