I have a form with an file field for images, a select option to choose album name, and a text field to type in a title.

I then loop this so it output 25 different rows which each of those 3 fields. The corresponding field names are upload[], album[] and title[].

Once the form is processed, it goes through all of the array indexes where there was a valid image, and completes all the corresponding thumbnail and resizing code and puts it into a database.

I just do not know how I can get all the album's and title's that correspond with the files to cycle through as well. I need those for when I insert a valid image path into the database.

Here is my processing code so far.

	$upload = $_POST['upload'];
			$title = $_POST['title'];
			$album = $_POST['album'];


		foreach($_FILES['upload'] as $file)
		{
			list($width, $length) = getimagesize($_FILES['upload']['tmp_name']);
			if ($width > 3000 || $length > 3000)
				{
				$errors = 1;
				$error .= "* One or more of your files dimensions are too large. (Must be less than 3000 x 3000) *";
				}
			$getimagesize = getimagesize($_FILES['upload']['tmp_name']);


			if ($getimagesize != true)
				{
					$errors = 1; 
					$error .= "* You have uploaded one or more files that are not images. (Images must be either .jpg, .jpeg, .gif or .png) *";
				}

			if($errors == 0)
				{
					$target = 'images/';
					$target = $target ."/". basename($_SESSION['username'].'_'.$_FILES['upload']['name']) ;
					$target = str_replace( " ", "_", $target );
					if ( ($_FILES['upload']['type'] == "image/jpeg") || ($_FILES['upload']['type'] == "image/jpg") || ($_FILES['upload']['type'] == "image/gif") || 			($_FILES['upload']['type'] == "image/png") || ($extension == "jpeg") || ($extension == "jpg") || ($_FILES['upload']['type'] == "image/pjpeg"))
							{
									if ($_FILES['upload']['size'] < 3000000)
											{
														if (is_uploaded_file($_FILES['upload']['tmp_name']))
																{


//Here I want to then move the file to a folder which I know how to do move_uploaded_file and then I need to somehow get the corresponding title and album with this image to put into a database.  

Any Ideas?

    a simple example:

    <?php
    if (!isset($_POST['submit']))
    {
    	echo '
    	<form action="" method="POST" enctype="multipart/form-data">
    
    1 file: <input type="file" name="1"><br>
    1 album: <select name="data[1][album]"><option value="one">one</option><option value="two">two</option><option value="three">three</option></select><br>
    1 title: <input type="text" name="data[1][title]"><br><br>
    
    2 file: <input type="file" name="2"><br>
    2 album: <select name="data[2][album]"><option value="one">one</option><option value="two">two</option><option value="three">three</option></select><br>
    2 title: <input type="text" name="data[2][title]"><br><br>
    
    3 file: <input type="file" name="3"><br>
    3 album: <select name="data[3][album]"><option value="one">one</option><option value="two">two</option><option value="three">three</option></select><br>
    3 title: <input type="text" name="data[3][title]"><br><br>
    
    <input type="submit" name="submit" value="submit">
    </form>
    ';
    }
    else
    {
    	echo '<pre>'; print_r($_POST['data']);  echo '</pre>';
    	echo '<pre>'; print_r($_FILES);  echo '</pre>';
    }
    ?>
    

      Should I just change each name to go along with my increment on the previous page.

      $i = 0;
      while($i < 25)
      {
      <input name="upload[$i]">
      <input name="title[$i][title]">
      <input name="album[$i][album]">
      }

      something basically like that?

        So pretty much what I am asking is how do I cycle between all 3 array variables at the same time on my processing page, so I can insert the Index 0 from each into my database, Index 1 from each into my database and so on.

          Write a Reply...