Using Apache/Unix
Hi I have this simple upload script that does upoad to temp and then uses the copy() command to copy it to a folder that I want.
However, it seems that the copy command does not accept variables. The $target variable is equal to "projects/username/file.zip" but when I use it in copy($path,$target) I get an error like if $target is NULL. Can thge copy() command take variuables in the second parameter?
The script is this:
<?php
isset($Username);
if ( $Username=="") header("Location: $page");
$dir=trim(strtolower($Username));
$new_file = $userfile_name;
$newfilename = "projects/".$dir."/".$new_file;
$target = trim(strtolower($newfilename));
print $target;
function do_upload($filename) {
$file = basename($filename);
$tmp_upload_path = "/var/tmp//";
if (!move_uploaded_file($tmp_upload_path.$file, $target)) echo "failed to copy file<br>\n";
return;
}
?>
<HTML>
<HEAD>
<TITLE>PHP - file upload</TITLE>
<style type="text/css">
<!--
body { font-family: Arial, Helvetica, sans-serif; font-size: 10pt}
-->
</style>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#800080">
<?php
do_upload($userfile);
?>
<TABLE>
<TR>
<TD><b>upload report</b></TD><TD></TD>
</TR>
<TR>
<TD>file name:</TD><TD><?php echo $userfile_name; ?></TD>
</TR>
<TR>
<TD>file size:</TD><TD><?php echo $userfile_size; ?></TD>
</TR>
<TR>
<TD>file type:</TD><TD><?php echo $userfile_type; ?></TD>
</TR>
</TABLE>
</BODY>
</HTML>
for this script I get an error:
projects/malebuffy/logo2.jpg // This is the $target value
Warning: Unable to create ": Is a directory in /opt/apache/htdocs/symbian/vhost/html/upload_go.php on line 23
Warning: Unable to move '/var/tmp//php6JayO2' to " in /opt/apache/htdocs/symbian/vhost/html/upload_go.php on line 23
failed to copy file
upload report
file name: logo2.jpg
file size: 12928
file type: image/pjpeg
Please help. How can I make it upload in a variable folder according to the value of $username?
Thanx in advance!