Jump to content

Recommended Posts

This is what I am trying to accomplish.  I have a site that users can upload images to and they go into a "to be checked" directory.  In my website admin panel, the contents of this directory are gathered and the images are displayed for either acceptance or rejection.  I am able to get this part coded.  However, I would also like a way for me to add descriptions to the photos on this same page.  However, I can't seem to figure out how to associate a specific text field for each of these images so that after the form is POSTed I can recall which description went with what image.  Here is part of the code:

 

manage_photos.php

<?php
	include "PhotoManager.php";
	$photo_manager = new PhotoManager();
	$photo_process_dir = "uploads/photos/";
	$accepted_photos_dir = "../photos/";
	$rejected_photos_dir = "uploads/photos/rejected/";

	// are we processing photos or just viewing the list?
	if (isset($_POST["accept"]))
	{
		foreach($_POST["decision"] as $var)
		{
			**** THIS IS WHERE I NEED TO FIGURE OUT HOW TO GET THE DESC ****
			$photo_manager->addPhoto($var, $desc);
		}
	}
	else if (isset($_POST["reject"]))
	{
		foreach($_POST["decision"] as $var)
		{
			$photo_manager->rejfectPhoto($var);
		}
	}

	$photo_dir_handle = opendir($photo_process_dir);

	while ($current_file = readdir($photo_dir_handle))
		$file_list[] = $current_file;

	closedir($photo_dir_handle);

	sort($file_list);

	echo "<form id=\"decisionForm\" action=\"manage_photos.php\" method=\"POST\">\n";
	echo "<table border=1 cellpadding=1 cellspacing=1>\n";
	echo "<tr><th>Filename</th><th>Thumbnail</th><th>Decision?</th><th>Description</th></tr>\n";

	foreach ($file_list as $photo)
	{
		echo "<tr>\n";
		echo "<td>" . $photo . "</td>\n";
		echo "<td><img src=\"" . $photo_process_dir . $photo . "\" width=" . $thumb_width . " height=" . $thumb_height . "></img></td>\n";
		echo "<td><input type=\"checkbox\" name=\"decision[]\" value=\"" . $photo_process_dir . $photo . "\"></td>\n";
		echo "<td><input type=\"text\" name=\"desc[]\" value=\"\"></td>\n";
		echo "</tr>\n";
	}

	echo "</table>\n";
	echo "<br />";
	echo "<input type=\"submit\" name=\"accept\" value=\"Accept Checked\">\n";
	echo "<input type=\"submit\" name=\"reject\" value=\"Reject Checked\">\n";
	echo "</form>\n";
?>

 

The way it's set up, each row of the table has a checkbox at the end.  Depending on which submit button is clicked, all the selected images are either accepted or rejected.  Again, that all works fine. I just don't know how to get anything typed in the "desc[]" text boxes to associate with its given image.  I tried naming the text boxes based on the image, such as:

 

<input type=\"text\" name=\" . $photo_process_dir . $photo . "\" value=\"\">

 

Since whatever check boxes are selected will carry their value into the $_POST["decision"] array, I thought I could match up that value to the name of the textbox, but I've had no success.

Link to comment
https://forums.phpfreaks.com/topic/234014-post-ing-images-with-descriptions/
Share on other sites

would you want to use a database to store this information or would it be another method, such as a text file, with a name based on the image, and you write the description into the text file?

 

both processes would do the job and wouldn't be too hard to do. I would say with the arrays it should correspond that the keys for both descision and description would match so loop through one array using key and value should do it

$desc = $_POST['desc'];
foreach($_POST["decision"] as $key =>$var)
		{
			**** THIS IS WHERE I NEED TO FIGURE OUT HOW TO GET THE DESC ****
                                $photo_manager->addPhoto($var, $desc[$key]);
		}

 

I am not sure if the code is quite correct, as I have never tried it but I am sure it would work like this, since both arrays should have the corresponding keys matching the image to the description

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.