I have been working on making this work for a while now. The file seems to upload correctly (I echo the $userfile variable to make sure it looks right) but it will not copy to my web directory. Just to see if all the paths were correct I copied a file to the /tmp directory using the shell. Then I ran the script and copied that file to the web directory rather than $userfile. That worked! Still when I try to copy $userfile to the web directory I always get the following output to the browser: /tmp/phpJHw39j Can't copy Dances.gif to /home/jzdoesit/www/test/Dances.gif. (/tmp/phpJHw39j is there because I echo $userfile) Here is the code:
<?
// file_upload.php
$archive_dir = "/home/jzdoesit/www/test";
function upload_form() {
global $PHP_SELF;
?>
<FORM METHOD="POST" enctype="MULTIPART/FORM-DATA" ACTION="<? echo $PHP_SELF ?>">
<input type="hidden" name="action" value="upload">
Upload file!
<INPUT TYPE="FILE" NAME="userfile" >
<INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="UPLOAD">
</FORM>
<?
}
function upload_file() {
global $userfile, $userfile_name, $userfile_size, $userfile_type, $archive_dir, $WINDIR;
// The file seems to be uploading correctly because when I echo userfile it looks correct
echo "$userfile ";
if(isset($WINDIR)) $userfile = str_replace("\\\\","\\", $userfile);
$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];
$filename = basename($userfile_name);
// I moved the file below to the /tmp directory using the shell
$test = "/tmp/Logo.gif";
if($userfile_size <= 0) die ("$filename is empty.");
// When I substite $test for $userfile below, everything works
//....it only has a problem copying the php created file stored in $userfile
if(!@copy($userfile, "$userfile/$filename"))
die("Can't copy $userfile_name to $archive_dir/$filename.");
echo "$filename has been successfully uploaded.<br>";
}
?>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<?
if ($action == 'upload') upload_file();
else upload_form();
?>
</body>