
August 30th, 2003, 11:24 AM
|
|
Contributing User
|
|
Join Date: Dec 2002
Location: Knoxville, Tennessee (U.S.A.)
Posts: 58
Time spent in forums: 5 m 15 sec
Reputation Power: 6
|
|
|
"copy()" Function Not Working With File Upload
Below is a multiple-file upload script. The form input part works ok. The variables $FileType, $FileName, $FileSize, $TempName, and $FileError work fine. But just after $FileError (which does not output an error message) the script just stops. The problem appears to be with the "copy()" function. I can simplify the script, make it just a single file upload script, use the variable $userfile for the first part of the "copy() function, and it uploads the file just fine.
The problem is when I try to make it a multiple-file upload script like the one below - then the copy function won't work.
I would appreciate if anyone could spot the problem.
PHP Code:
$Admin[UploadNum] = "10";
if($FileUpload) {
for ($Number = 1; $Number <= $Admin[UploadNum]; $Number++){
if ($FileUpload) {
$FileType = $_FILES["userfile"."$Number"]["type"];
$FileName = $_FILES["userfile"."$Number"]["name"];
$FileSize = $_FILES["userfile"."$Number"]["size"];
$TempName = $_FILES["userfile"."$Number"]["tmp_name"];
$FileError = $_FILES["userfile"."$Number"]["error"];
echo "File Type: $FileType<p>"; // $FileType prints out fine.
echo "File Name: $FileName<p>\n"; // $FileName prints out fine.
echo "File Size: $FileSize<p>\n"; // $FileSize prints out fine.
echo "Temporary Name: $TempName<p>\n"; // $TempName prints out fine.
echo "Error Message: $FileError<p>\n"; // Does not output error message - appears to work fine.
// ------------ The script stops working right here ------------
if (copy ($_FILES['userfile'.'$Number']['name'], "users/".$_FILES["userfile"."$Number"]["name"]."")) {
echo "Your file was successfully uploaded!<p>\n";
} else {
echo "Your file could not be copied.<p>\n";
}
}
}
unlink ($userfile);
}else{
echo "<form action=\"$PHP_SELF\" enctype=\"multipart/form-data\" method=\"post\">\n";
for ($Number = 1; $Number <= $Admin[UploadNum]; $Number++){
echo "<input name=\"userfile"."$Number\" type=\"file\" size=\"25\">\n";
}
echo "<input name=\"FileUpload\" type=\"submit\" value=\"Upload Files\"></form>\n";
}
Thanks.
Volitics
__________________
Thomas Jefferson: "Democracy will work only until the political incumbents discover they can perpetuate themselves in office by taxing the industrious to bribe the indolent."
|