...

View Full Version : cant get in the files array



subhailc
06-13-2005, 09:16 PM
this works

<?php copy ($_FILES['f']['tmp_name'], $_FILES['f']['name']); ?>


but when trying to access the files array for multiple uploads, i'm stumped. i've tried each of the following with inputs named f and f[]

foreach($_FILES['f'] as $file) copy($file['tmp_name'], $file['name']);
foreach($_FILES as $file) copy($file['f']['tmp_name'], $file['f']['name']);
foreach($_FILES['f']['tmp_name'] as $file) copy($file, $_FILES['f']['name']);


any insight would be greatly appreciated.

AaronW
06-13-2005, 10:24 PM
Actually the first one should work.


<input type="file" name="files[]">
<input type="file" name="files[]">
<input type="file" name="files[]">

foreach ($_FILES['files'] as $file)
{
copy ($file['tmp_name'], $file['name']);
}

subhailc
06-14-2005, 02:29 AM
hi aaron, thanks for taking the time to reply.

i'm still getting the following error returned
Warning: Invalid argument supplied for foreach()

i added line break and curlies just in case, still no good. permissions are set properly, and i'm able to upload fine to the same directory - if i just take the foreach bit out the script works fine so i don't suppose it could be a conflict with php installations - i'm stumped. perhaps i'm missing something simple; complete test follows:
<html><body>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="file" name="file[]" />
<input type="submit" name="submit" />
<?php if(isset($submit)) foreach($_FILES['file'] as $file) copy($file['tmp_name'], $file['name']); ?>
</form>
</body>
</html>
that doesnt work, in the same dir this does

<html><body>
<form method="POST" action="<? echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<input type="file" name="singlefile" />
<input type="submit" name="submit" />
<?php if(isset($submit)) copy($_FILES['singlefile']['tmp_name'], $_FILES['singlefile']['name']); ?>
</form>
</body>
</html>

Nightfire
06-14-2005, 02:34 AM
Try using curly braces aswell in your code {}



<?php
if(isset($_POST['submit'])){
foreach($_FILES['file'] as $file){
copy($file['tmp_name'], $file['name']);
}
}
?>

subhailc
06-14-2005, 07:14 AM
i added line break and curlies just in case i tried switching it up, and it wasnt any help. does that script work for you nightfire? am i to assume the problem is with the host and note the code? thanks for your input.

subhailc
06-14-2005, 08:04 AM
wierd - not the host, i tried same code on two other servers - again the single upload works fine, but can't get into the files array - not even for an echo output. curiously, this does work
<?php for ($i=0;$i<4;$i++) copy($_FILES['file']['tmp_name'][$i], $_FILES['file']['name'][$i]); ?>i'm still mystified, but at least operational.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum