Ok well here's the code I use... notice the command stripslashes(), mkdir() and unlink() functions, all are used to prevent the most common errors with file uploads.
~upload.php~
<?
if(isset($FILE))
{
$fileroot = $GLOBALS["DOCUMENT_ROOT"].'/files/';
//Make sure directory exists, if not then create it
@mkdir($fileroot, 0777);
if (strlen($FILE_name)>0)
{
//Strip double /'s (Common error on Win32 systems)
$tempfile = stripcslashes($FILE);
$newfile = $fileroot.$FILE_name;
//If file by same name already exist then delete it (else copy function will fail)
@unlink($oldfile);
echo 'Copying file "'.$tempfile.'" to "'.$newfile.'", please wait...<br>';
if(@copy($tempfile, $newfile))
echo 'File "'.$FILE_name.'" Copied Successfuly.<br><br>';
else
echo 'ERROR - File "'.$FILE_name.'" Copied Failed.<br><br>';
}
else
echo 'ERROR - Filename is blank, please try again<br><br>';
}
?>
<form enctype="multipart/form-data" action="/upload.php" method="POST" name="FormUpload">
Filename:<input type="file" size="28" name="FILE"><input type="submit" name="submit">
</form>
The name of the form item FILE can be anything, I just use FILE for simplicity. It can also be an array for use with multiple file uploads...
Example:
Filename 1:<input type="file" size="28" name="FILE[]"><input type="submit" name="submit"><br>
Filename 2:<input type="file" size="28" name="FILE[]"><input type="submit" name="submit">
You would then get these files using the following arrays.
FILE[] - Contains the temp file names
FILE_name[] - Contains the actual file names
FILE_size[] - Contains the file sizes
So for the 1st file you would get it like so.
$tempfile = FILE[0];
$filename = FILE_name[0];
$filesize = FILE_size[0];
Anyways yer not the only one who had problems with the tutorials upload code, hope ya have better luck with mine. 🙂