Replace multiple images at once

I am working on a website where the gallery photos are extremely seasonal related. The site owner would like to be able to replace all images at once instead of first deleting all images and afterwards uploading new ones or the other way arround.

I know how I can delete multiple photos at once using a checkbox with each image and after that loop over the results and delete them from the database, i.e.

foreach ($photos as $photo)
{
	$thumb_file = $thumb_path . $photo['photo'];
	$photo_file = $photo_path . $sphoto['photo'];		
	if (file_exists($thumb_file))
	{
		unlink($thumb_file);
	}
	if (file_exists($photo_file))
	{
		unlink($photo_file);
	}			
}		
$this->media->delete_gallery_fotos($_POST['delete_id']);

I am also familiar on how to upload multiple photos at once i.e.

for ($i = 0; $i < count($_FILES['file']['name']); $i++)
{
...... //rest of function
}

But I have no idea how to combine these two into one. Every help would be highly appreciated

Thank you in advance

Use one form that includes upload and deletion. Serverside code just has to follow each other.

Do you want to delete all the old photos - empty the folder - or select which ones to delete?

@chorn & @Rubble. Thanx both for the reaction. @Rubble. If it is possible It would be nice If I could elect wich ones to delete

In that case you will need to as you say use check boxes to select the images to delete. Personally I would stick with two forms. Otherwise you will have one complicated piece of code.

Anyway as @chorn says you will need one form which reads the image folder and populates the page with a thumbnail of the image and a checkbox. Below that you will need a second part of the form with the input boxes for the new photos.

Once the form is submitted - either a new page or to the same page - you will need to check both arrays and if either is populated then run either the delete code, upload code or both.

I would start off getting both the delete and upload codes working independently and then when they are working join them into the one form. It should just be a matter of removing one submit button, end of form and start of form.

Out of interest are you relying on the site owner resizing the images before uploading them? I find they can not always be trusted to do it!

@Rubble. Thanx again for the reply. I will try this approach.

About resizing the images; So far I used zebra_image.php to handle the resizing. If you don’t know it? This is the link to the lib

Just thought I would check as in the past I have told users to resize on their PC and after a while they just upload the full size images which breaks everything!

I have written myself a few galleries in the past but the backend is usually a mess as I am the only one using it.

I do my resizing etc. with Imagemagick and I decided not to have categories this time and any photo that is over a year old is automatically moved to the old photos gallery.

If you had some way of automatically identifying the images to delete you could do the same with yours. Perhaps add a prefix when renaming them or over a certain age etc.

1 Like

@Rubble That is a nice way to do it indeed. For sure I’m going to think about that

If the images are all in one directory I would be tempted to:

  1. upload the new images to a temporary folder
  2. rename the existing image folder to images-archived
  3. rename the temporary folder to images-folder

Yes, or just identify the images to the season somehow, either in a database or just by folder name, then when the season comes around again, the site owner can just point the site back to the images that were used this season last year. Unless it’s not that kind of seasonal.

@John_Betong & @droopsnoot Thank you both for the reply. That’s what I probably would do as well, but he simply don’t want to keep the images on the server. He simply want to replace them with new images

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.