Re: Arrays from forms....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gary E. Terry wrote:
I have a problem. I have done this before, but can't find the files.
I am using the following function to upload files from a form.

foreach ($_FILES["pictures"]["error"] as $key => $error) {
   if ($error == UPLOAD_ERR_OK) {
       echo "$error_codes[$error]";
       move_uploaded_file(
         $_FILES["pictures"]["tmp_name"][$key],
         "images/" .$_FILES["pictures"]["name"][$key]
       ) or die("Problems with upload");
   }
}

I also need to insert the filenames of the uploaded files into a database.

There are three fields in my db for these filenames, image1 image2 and
image3.
What would be the best way to get those filenames from the array into the
vars $image1 $image2 and $image3?

You want variable variables:

http://www.php.net/manual/en/language.variables.variable.php

<?php
for ($i = 1; $i < 5; $i++) {
  ${"image".$i} = "i is " . $i;
}
echo $image4 . "\n";
?>

i is 4


so after the or die:

${"image".$key} = $_FILES['pictures']['name'];

--
Postgresql & php tutorials
http://www.designmagick.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux