There is not enought information about your script. I would like to know if you are using MySQL ou other type of DB?
Anyway, to choose new images you nedd to create a form lwith these fields:
Image1: <input type="file" name="image1" ><input type='hidden' name='old_image1' value="$oldimage1">
Image2: <input type="file" name="image2" ><input type='hidden' name='old_image2' value="$oldimage2">
Image3: <input type="file" name="image3" ><input type='hidden' name='old_image3' value="$oldimage3">
Image4: <input type="file" name="image4" ><input type='hidden' name='old_image4' value="$oldimage4">
<input type='hidden' value='$id' name='id_of_the_record'>
Don“t forget to put in the <form> tag: enctype="multipart/form-data".
Then you have 2 steps:
- Delete the old files
- Put the new files inside of the directory and save the names of the files to the database.
Firstly you verify if was choosed a new image 1:
if($image1!=""){ ..... }
If $image1 is not empty you unlink the old image which name is $old_image1. Then you use UPDATE query to save the new image name to DB.
You repeat the same with the other images.
To put the new image you can use that:
if (copy ($image1,"$directory".strtolower($image1_name))) {
echo "success";
}else{
echo "failed";
}
So it will be something like that for image1:
$directory = "mydirectory/";
if($image1!=""){
if(unlink("$directory".$old_image1."")){
if (copy ($image1,"$directory".strtolower($image1_name))) {
echo "success";
}else{
echo "failed";
}
}
//here you need to put your UPDATE query, my example is MySQL
$sSQL = UPDATE images SET image1='$image1_name' WHERE id=$id_of_the_record
mysql_query($sSQL) or die(mysql_error()."<br>".$sSQL);
}