Re: Arrays from forms....

From: Date: Thu, 30 Nov 2006 23:21:19 +0000
Subject: Re: Arrays from forms....
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-42780@lists.php.net to get a copy of this message
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/

« previous php.db (#42780) next »