Hey all, here's a weird one... I am able to to a multiple file upload on a blank page using the following code:
$path_to_file = '../uploads';
$files = $HTTP_POST_FILES['userfile'];
echo "file: ", $FILES['userfile']['name'][0];
if (!ereg("/$", $path_to_file))
$path_to_file = $path_to_file."/";
foreach ($files['name'] as $key=>$name) {
if ($files['size'][$key]) {
// clean up file name
$name = ereg_replace("[a-z0-9.]", "", str_replace(" ", "", str_replace("%20", "", strtolower($name))));
$location = $path_to_file.$name;
while (file_exists($location))
$location .= ".copy";
copy($files['tmp_name'][$key],$location);
unlink($files['tmp_name'][$key]);
print "Successfully uploaded file: $name.\n";
}
}
This works perfectly. If I copy and paste it to another page with images, other php scripts(that I commented) and java scripts it doesn't work! I get the following error:
Warning: Invalid argument supplied for foreach()
If i put this in my code: echo "file: ", $HTTP_POST_FILES['userfile']['name'][0];
it will print out: "file: "
I i put this in my code: echo $userfile[0]; it prints out the entire path and filename(c://entire/path/and/filename.jpg)
What I don't understand is why does it work in a blank test page and not in the page I really want it!