I hope this is the right spot to ask this since it does require both php and mysql. As part of a client login website I am working on, one of the features is the ability to upload a document/file to a directory that belongs to another user. Let me take one step back however before I go any further. The directory is created upon client signup and the name of the folder is based off of their username to login. Their username is in a table called users. Ok, now back to where we were....
I currently have just the html upload form with a dynamic drop down menu that lists users by their username, straight from the users table. Please see the form
<form action="../../globals/upload.php" method="post" enctype="multipart/form-data" name="docform" id="docform">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td width="43%" bgcolor="#F0F0F0">Find It:</td>
<td width="57%" bgcolor="#F8F8F8">
<div align="left">
<input name="file" type="file" size="15">
</div></td>
</tr>
<tr>
<td bgcolor="#F0F0F0">Destination:</td>
<td bgcolor="#F8F8F8"><div align="left"><?
$sql = "SELECT id, user_name FROM users";
$result=mysql_query($sql);
$options="";
while ($row=mysql_fetch_array($result)) {
$id=$row["id"];
$thing=$row["user_name"];
$options.="<OPTION VALUE=\"$id\">".$thing;
}
?>
<SELECT NAME=users>
<OPTION VALUE=0>Choose
<?=$options?>
</SELECT> </div></td>
</tr>
<tr>
<td colspan="2" bgcolor="#F0F0F0"><div align="center">
<INPUT TYPE="hidden" name="MAX_FILE_SIZE" value="200000">
<input type="submit" name="Submit" value="Add New Document">
</div></td>
</tr>
</table>
</form>
Ok so theres the form. Nothing fancy to it. The form calls to upload.php to do the dirty work. My upload script needs help. Here's what I got
session_start();
header("Cache-control: private"); // IE 6 Fix.
$user_name = $_SESSION['user_name'];
require '../globals/dbconnect.php';
$filename=$_POST['file'];
$users=$_POST['users'];
$folder = "../usrfiles/".$_POST['users']."";
$old = umask(0);
chmod("../usrfiles/".$_POST['users']."", 0777);
umask($old);
if (is_writable($filename)) {
if (!$upload = fopen($filename, 'a'))
{
echo "Cannot open file ($filename)";
exit;
}
if (fwrite($upload) === FALSE)
{
echo "Cannot write to file ($folder)";
exit;
}
echo "Success, uploaded ($filename) to ($folder)";
fclose($upload);
}
else
{
echo "The folder = $folder is not writable";
}
So upon execution of the script, I get this error on screen
Notice: Undefined index: file in C:\Program Files\Apache Group\Apache2\htdocs\from scratch\globals\upload.php on line 6
Warning: chmod(): No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\from scratch\globals\upload.php on line 10
The folder = ../usrfiles/1 is not writable
Line 6 is; $filename=$_POST['file'];
Line 10 is; chmod("../usrfiles/".$_POST['users']."", 0777);
Suggestions?