Hello again,
I have tried to do this a number of ways and no luck yet. Maybe someone here can figure out what I'm doing wrong. I have a database with a table called users. The fields are id, user_name, password (of course) and groups. Now I have an upload form with a dynamic drop down list that selects users from the user_name field. The idea here is so that the currenltly logged in user can select a name from that drop down and upload something to their folder. The folders mirror the names in the user_name field.
When I try to upload, I get this error;
Warning: copy(4/p2.pdf): failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\from scratch\usrfiles\upload.php on line 18
An error occurred during your upload. Please try renaming your file and uploading it again.
The funny thing with that error is that where you see the number 4, thats actually the id number for the user in the users table. So it is connecting to the table, but the username chosen on the form is not matching up to the name of the folder. Here's the form on index.php
<form action="../../usrfiles/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="f_filename" type="file" id="f_filename" 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=user_name id="user_name">
<OPTION VALUE=0 selected>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="hidden" name="step" value="doupload">
<input type="submit" name="Submit" value="Add New Document">
</div></td>
</tr>
</table>
</form>
Heres the php that does the dirty work aka upload.php
session_start();
header("Cache-control: private"); // IE 6 Fix.
$user_name = $_POST['user_name'];
require '../globals/dbconnect.php';
$sql="SELECT user_name FROM users";
if ($step == 'doupload')
{
$internal_error_msg = '';
$upload_dir = ''.$user_name.'';
$today = date("F j, Y, g:i a");
if ($f_filename_size < 8000000000)
{
#echo "f_filename: $f_filename<BR>\n";
#echo "f_filename_name: $f_filename_name<BR>\n";
#echo "f_filename_size: $f_filename_size<BR>\n";
#echo "f_filename_type: $f_filename_type<BR><BR>\n";
if (copy($f_filename, "$upload_dir/$f_filename_name"))
{
echo "$f_filename_name uploaded successfully. ($f_filename_size bytes.)";
$fp = fopen ("$upload_dir/upload.log", "a+");
fwrite($fp, "$today - $f_filename_name uploaded successfully. ($f_filename_size bytes.)\n");
fclose($fp);
}
else
{
# An error occurred during your submission.
$internal_error_msg .= '<DIV class="contentwarning">An error occurred during your upload. Please try
renaming your file and uploading it again.</DIV>';
}
}
else
{
# File too large.
$internal_error_msg .= '<DIV class="contentwarning">The file is too large.</DIV>';
}
unlink($f_filename);
if ($internal_error_msg != "")
{
echo $internal_error_msg;
echo '<BR>';
}
}
Any suggestions? 😕