Folder Creation Script Problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lip9000
Forum Newbie
Posts: 11
Joined: Tue Jul 04, 2006 3:38 am

Folder Creation Script Problem

Post by lip9000 »

I've got a form that calls a php script to create a folder. These folders are used as albums for a photo gallery. The script that gets called looks like this:

Code: Select all

<?php
if ((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1")) {
 
 $name = $_POST['name'];
 $path = "C:/wamp/www/mirrabookahs/gallery/albums/$name";
 

mkdir($path,0755);  

 
$updateGoTo = "listalbums.php";
  }
 
 header(sprintf("Location: %s", $updateGoTo));

?>
Currently when I run my form I get this:
"Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\mirrabookahs\admin\gallery\createfolder.php on line 8"

So the script doesn't like the $name variable being in the path, but I need it because thats the name of the folder that gets entered in the form on the previous page.

If i change $path to $path = "C:/wamp/www/mirrabookahs/gallery/albums/My Folder Name"; sure enough "My Folder Name" gets created in the directory, but as soon as I change it to a variable it doesn't work.

Even if i change

Code: Select all

mkdir($path,0755);
to

Code: Select all

mkdir('C:/wamp/www/mirrabookahs/gallery/albums/$name',0755);
I get the same error.

Is there anyway I can put that variable in a way that will actually work? Thanks in advance
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

<?php
error_reporting(E_ALL); ini_set('display_errors', true);

if ( (isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form1") ) {
  $path = 'C:/wamp/www/mirrabookahs/gallery/albums/'.$_POST['name'];
  echo '_POST[name]: ', $_POST['name'], "<br />\n";
  echo 'path: ', $path, "<br />\n";
 
  mkdir($path,0755); 
  $updateGoTo = "listalbums.php";
}
 
// header(sprintf("Location: %s", $updateGoTo));
?>
also keep in mind $_POST['name'] might include something like ..\..\..\..\boot.ini
lip9000
Forum Newbie
Posts: 11
Joined: Tue Jul 04, 2006 3:38 am

Post by lip9000 »

This is what comes up:

_POST[name]:
path: C:/wamp/www/mirrabookahs/gallery/albums/

Warning: mkdir() [function.mkdir]: File exists in C:\wamp\www\mirrabookahs\admin\gallery\createfolder.php on line 9


Here is what the form looks like:

Code: Select all

<form id="form1" name="form1" method="post" action="createfolder.php">
              <table width="405" cellpadding="5" cellspacing="1" class="adminTable">
                <tr>
                  <td width="136" height="31" class="h1Black"><div align="right" class="style3">Album Name:</div></td>
                  <td width="260"><label>
                    <input name="name" type="text" class="Fieldinput" id="name" size="40" />
                  </label></td>
                </tr>

                <tr>
                  <td height="31"><input name="MM_update" type="hidden" id="MM_update" value="form1" />
                  <input name="name" type="hidden" id="name" value="<?php echo $_POST['name']; ?>" /></td>
                  <td><label>
                    <input name="button2" type="submit" class="Buttoninput" id="button2" value="Add Album" />
                  </label></td>
                </tr>
              </table>
            </form>
Post Reply