create directory in windows IIS

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
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

create directory in windows IIS

Post by lmh85 »

i had this code running well when i'm using apache.. But i need to make it runable in IIS.. anybody help?

Code: Select all

<html>
<?php
include '../config.php';
include '../opendb.php';
?><head>
<title>(Add Product)</title>
<script language="javascript" event="onclick" for="btnAdd" runat="server">
if(document.frmAdd.txtBrand.value == "")
{alert("Please enter the brand name before adding..");
document.frmAdd.txtBrand.focus();
window.event.returnValue = false;
}
else if(document.frmAdd.txtLink.value == "")
{alert("Please enter the link before adding..");
document.frmAdd.txtLink.focus();
window.event.returnValue = false;
}
else if(document.frmAdd.txtFolder.value == "")
{alert("Please enter the Folder Name before adding..");
document.frmAdd.txtFolder.focus();
window.event.returnValue = false;
}else if(document.frmAdd.flLogo.value == "")
{
alert("Please select a file to upload as the Logo");
document.frmAdd.flLogo.focus();
window.event.returnValue = false;
}
</script>
</head>

<body>
<form name="frmAdd" method="post" action="<?php
echo $PHP_SELF;?>" enctype="multipart/form-data">

<table id="brand">
<tr>
    <td colspan="2">Please enter the mandatory fields(<font color="#FF0000">*</font>)</td>
</tr>
<tr>
    <td><font color="#FF0000">*</font>Brand name:</td>
<td><input type="text" value="" name="txtBrand"></td>
</tr>
<tr>
    <td><font color="#FF0000">*</font>Link:</td>
<td><input type="text" value="" name="txtLink"></td>
</tr>
<tr>
<td><font color="#FF0000">*</font>Folder Name:</td>
<td><input type="text" value="" name="txtFolder"></td>
</tr>
<tr>
<td><font color="#FF0000">*</font>File to upload/store in database:</td>
<td> <input type="file" name="flLogo"  size="40"></td>
</tr>
<tr><td colspan="2" align="right"><input type="submit" value="Add" name="btnAdd"></td></tr>
</table>
<?php
if(isset($_POST['btnAdd']))
{
 $result=mkdir('../customer/'.$_POST['txtFolder']. 0777);
   if(!$result){
	  print("Error: Couldn't create the directory!<BR>");
   }else{
		$uploadDir = '../customer/'.$_POST['txtFolder']."/";
		$tmpName = $_FILES['flLogo']['tmp_name'];
		$fileName = $_FILES['flLogo']['name'];
		$filePath = $uploadDir . $fileName;
		$result = move_uploaded_file($tmpName, $filePath);
			if(!$result){
				print("Error uploading file");
				exit;
			}
			if(!get_magic_quotes_gpc())
			{
				$fileName=addslashes($fileName);
				$filePath=addslashes($filePath);
			}
		$query = "INSERT INTO tblBrand (strBrand,strLink,strImgLink,strFolderName ) "."VALUES ('".$_POST['txtBrand']."', '".$_POST['txtLink']."', '".$_POST['fileName']."', '".$_POST['txtFolder']."')";
		mysql_query($query) or die('Error, query failed : '.mysql_error()); 
		print("files updated");
	}//result(creating dir)
}//btnAdd
function remove_directory($dir) {
if($handle = opendir("$dir")) {
	 while (false !== ($item = readdir($handle))) {
     if ($item != "." && $item != "..") {
       if (is_dir("$dir/$item")) {
         remove_directory("$dir/$item");
       } else {
         unlink("$dir/$item");
         echo " removing $dir/$item<br>\n";
       }
     }
   }
   closedir($handle);
   rmdir($dir);
   echo "removing $dir<br>\n";
  }
}
if ($_GET['removeId'] != "" && $_GET['folderName'] !=""){
remove_directory("../customer/$folderName");
$query = "DELETE FROM tblBrand WHERE intId='$removeId';";
			mysql_query($query) or die('Error, query failed : '.mysql_error()); 
			print("Deleted");
}
include './brandContent.php';
include '../closedb.php';
?></form>
</body>
</html>
Last edited by lmh85 on Wed Dec 06, 2006 6:41 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

It's supposed to do what (exactly)? Is doing what (exactly)?
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

Post by lmh85 »

it will insert a row into a table in mysql then will create a directory in customer folder. then will add in a file in the new directory.
it will delete when it click on link which shows "X".

this is the part where it shows everything. including the file(a picture). If the user click on X, then it will delete the file, then the directory.

Code: Select all

<?php
$result=@mysql_query("SELECT intId,strBrand,strLink,strImgLink,strFolderName FROM tblbrand");
	if (!$result){
	print("<p>Woops.. there's nothing in the folder yet : ".mysql_error()."</p>");
	}else{
		print("<table border=\"1\"><tr>");
		print("<td>Remove</td><td>Brand Name</td><td>Link</td><td>Image</td><td>Folder Name</td></tr>");
		while($row=mysql_fetch_array($result,MYSQL_NUM)){
		print("<tr><td><a href=\"./index.php?removeId=$row[0]&folderName=$row[4]\">X</a></td>");
		print("<td>$row[1]</td>");
		print("<td><a href=\"$row[2]\" target=\"_blank\">$row[2]</a></td>");
		print("<td><img src=\"../customer/$row[4]/$row[3]\"></td>");
		print("<td>$row[4]</td>");
		}
		print("</tr></table>");
	}
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Ok, that's what it's supposed to do, I guess.
What is it doing right now? I.e. what exactly is the problem?
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

Post by lmh85 »

when i just cut and copy it to the place where IIS resides, it just can't work and shows me that page cannot be found. i'm able to remove, insert and all those mentioned above in apache. is there any difference in coding in regards to IIS and apache?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

lmh85 wrote:when i just cut and copy it to the place where IIS resides, it just can't work and shows me that page cannot be found.
I.e. you get a 404 doc not found error?
Same with simply

Code: Select all

<?php phpinfo(); ?>
as contents of that file?
Then this is a configuration issue and you should check http://www.php.net/manual/en/install.windows.php
lmh85
Forum Commoner
Posts: 49
Joined: Sat Oct 28, 2006 10:49 am

Post by lmh85 »

nope.. i got the following page..

Internet Explorer cannot display the webpage

Most likely causes:
You are not connected to the Internet.
The website is encountering problems.
There might be a typing error in the address.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

That's a IE "friendly message" error page.
Sorry, I don't have an IE here and don't know by heart (anymore) how to fetch the actual error code.
Post Reply