Jump to content

[SOLVED] newbie question


jtown

Recommended Posts

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

Link to comment
Share on other sites

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);

 

?>

Link to comment
Share on other sites

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 ..

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.