Page 1 of 1

create directory in windows IIS

Posted: Mon Nov 06, 2006 6:55 am
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>

Posted: Mon Nov 06, 2006 7:25 am
by volka
It's supposed to do what (exactly)? Is doing what (exactly)?

Posted: Mon Nov 06, 2006 8:08 am
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>");
	}
?>

Posted: Mon Nov 06, 2006 8:10 am
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?

Posted: Mon Nov 06, 2006 9:39 am
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?

Posted: Mon Nov 06, 2006 9:50 am
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

Posted: Mon Nov 06, 2006 10:34 am
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.

Posted: Mon Nov 06, 2006 10:42 am
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.