Well, I must say that I am new to working with FTP and am having problems
despite the good help I have recieved. I have been working with
code supplied by Janwillem Borleffs and have been able to get it to
connect to the ftp server on my dev machine (red hat/apache). What I am
trying to do is create a directory but the directory is not being created
(at least I don't see it in the expected directory) from an administrative
form so that annonomous users can upload files into it.
I think I am missing something here.
this
opens the ftp connection. This address hosts several dev sites
including the one I need to create a directory in which I will name
site1_root. The URL to the site on my dev machine is
"192.168.0. 219/site1_root". (what I type in the bwroser to get to the home
page).
This
is
supposed to change directories. If I understand it correctly, this code is
writing to the handle($ftp) which should allow it to point to the proper
folder
where I want to create the new folder.
Below is the code for the whole page: When try to execute it, I get no
error msgs from the fputs command, but
fails and let's
me know the folder does not exist.
The uploads folder has permissions set to '0777' for now.
I guess I'm all over the place in my comments here ... and I hate to ask
this question, but why doesn't this work?
Irvin <><
_______________ _______________ _______________ ______________
<html>
<head>
<title>Untitl ed Document</title>
<meta name="robots" content="noinde x">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$errTxt="";
if($Submit) {
if (!file_exists(" ../uploads/custum/".$folderna me)) {
$user = 'username';
$pass = 'password';
$dirname = "../uploads/custum/".$folderna me;
// Connect
$ftp = fsockopen("192. 168.0.219", 21, $errno, $errstr, 30);
fputs($ftp, "cwd /site_root/uploads/custom");
if (!$ftp) {
echo "$errno: $errstr<br>\n";
}else{
// Authenticate
if(!fputs($ftp, "user $user\r\n")) { echo "User Failed.<br>"; }
fgets($ftp, 1024);
if(!fputs($ftp, "pass $pass\r\n")) { echo "Pass Failed.<br>"; }
fgets($ftp, 1024);
// Make dir
if(!fputs($ftp, "mkd $dirname\r\n")) { echo "MKDIR Failed.<br>"; }
// Close
fputs($ftp, "quit\r\n") ;
fclose($ftp);
}
if (!file_exists(" ../uploads/custum/".$folderna me)) {
$errTxt.="An unidentified error was encountered while<br> trying to
create the folder <b>'uploads/custum/$foldername'</b>.";
}else{
$errTxt.="<font-color='green'>T he folder
<b>'uploads/custum/$foldername'</b> was sucessfully created.</font>";
}
}else{
$errTxt.="The folder <b>'uploads/custum/$foldername'</b> already esists.";
}
}
?>
<form name="form1" method="post" action="">
<table width="321" border="0" align="center" cellpadding="5"
cellspacing="0" bgcolor="#CCCCC C">
<tr bgcolor="#FFFFF F" class="mainhead ing">
<td><p>Add a New Custum Folder <span class="content" ><br>
</span></p> </td>
</tr>
<tr class="content" >
<td align="right">< div align="center"> Enter the name of the folder
you wish to add:</div></td>
</tr>
<tr class="content" >
<td align="right">< div align="center">
<input name="foldernam e" type="text" class="content" id="foldername "
value="<?php echo $foldername?>" size="50">
</div></td>
</tr>
<tr class="content" >
<td><div align="center">
<input name="Submit" type="submit" class="content" value="Add
Folder">
</div></td>
</tr>
<tr class="content" >
<td><div align="center"> <span class="contentB oldRed"><?php echo
$errTxt ?></span></div></td>
</tr>
<tr class="content" >
<td bgcolor="#FFFFF F"><div align="center"> <a href="browse.ph p">Return
to Folder Contents </a></div></td>
</tr>
</table>
</form>
</body>
</html>
despite the good help I have recieved. I have been working with
code supplied by Janwillem Borleffs and have been able to get it to
connect to the ftp server on my dev machine (red hat/apache). What I am
trying to do is create a directory but the directory is not being created
(at least I don't see it in the expected directory) from an administrative
form so that annonomous users can upload files into it.
I think I am missing something here.
this
Code:
$ftp = fsockopen("192.168.0.219", 21, $errno, $errstr, 30);
including the one I need to create a directory in which I will name
site1_root. The URL to the site on my dev machine is
"192.168.0. 219/site1_root". (what I type in the bwroser to get to the home
page).
This
Code:
fputs($ftp, "cwd /site1_root/uploads/custom");
supposed to change directories. If I understand it correctly, this code is
writing to the handle($ftp) which should allow it to point to the proper
folder
where I want to create the new folder.
Below is the code for the whole page: When try to execute it, I get no
error msgs from the fputs command, but
Code:
if
(!file_exists("../uploads/custum/".$foldername)) {
me know the folder does not exist.
The uploads folder has permissions set to '0777' for now.
I guess I'm all over the place in my comments here ... and I hate to ask
this question, but why doesn't this work?
Irvin <><
_______________ _______________ _______________ ______________
<html>
<head>
<title>Untitl ed Document</title>
<meta name="robots" content="noinde x">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php
$errTxt="";
if($Submit) {
if (!file_exists(" ../uploads/custum/".$folderna me)) {
$user = 'username';
$pass = 'password';
$dirname = "../uploads/custum/".$folderna me;
// Connect
$ftp = fsockopen("192. 168.0.219", 21, $errno, $errstr, 30);
fputs($ftp, "cwd /site_root/uploads/custom");
if (!$ftp) {
echo "$errno: $errstr<br>\n";
}else{
// Authenticate
if(!fputs($ftp, "user $user\r\n")) { echo "User Failed.<br>"; }
fgets($ftp, 1024);
if(!fputs($ftp, "pass $pass\r\n")) { echo "Pass Failed.<br>"; }
fgets($ftp, 1024);
// Make dir
if(!fputs($ftp, "mkd $dirname\r\n")) { echo "MKDIR Failed.<br>"; }
// Close
fputs($ftp, "quit\r\n") ;
fclose($ftp);
}
if (!file_exists(" ../uploads/custum/".$folderna me)) {
$errTxt.="An unidentified error was encountered while<br> trying to
create the folder <b>'uploads/custum/$foldername'</b>.";
}else{
$errTxt.="<font-color='green'>T he folder
<b>'uploads/custum/$foldername'</b> was sucessfully created.</font>";
}
}else{
$errTxt.="The folder <b>'uploads/custum/$foldername'</b> already esists.";
}
}
?>
<form name="form1" method="post" action="">
<table width="321" border="0" align="center" cellpadding="5"
cellspacing="0" bgcolor="#CCCCC C">
<tr bgcolor="#FFFFF F" class="mainhead ing">
<td><p>Add a New Custum Folder <span class="content" ><br>
</span></p> </td>
</tr>
<tr class="content" >
<td align="right">< div align="center"> Enter the name of the folder
you wish to add:</div></td>
</tr>
<tr class="content" >
<td align="right">< div align="center">
<input name="foldernam e" type="text" class="content" id="foldername "
value="<?php echo $foldername?>" size="50">
</div></td>
</tr>
<tr class="content" >
<td><div align="center">
<input name="Submit" type="submit" class="content" value="Add
Folder">
</div></td>
</tr>
<tr class="content" >
<td><div align="center"> <span class="contentB oldRed"><?php echo
$errTxt ?></span></div></td>
</tr>
<tr class="content" >
<td bgcolor="#FFFFF F"><div align="center"> <a href="browse.ph p">Return
to Folder Contents </a></div></td>
</tr>
</table>
</form>
</body>
</html>