I have a form that takes in several images of homes to upload to the server, and store the path in my DB. The problem I'm having is if a file is not specified in the form (i.e. someone chooses not to upload a file for all possible entries) then my code stops at that particular selection.
heres a portion of the code so you can better understand what I mean.
//Copy main Pic
if($mainpic_name !="")
{
copy ("$mainpic", "./pictures/$mainpic_name")
or die("Main Picture: Could not copy file.");
echo "Main Picture: File $mainpic_name Uploaded Successfuly<br>";
}
else {die("No file specified.");}
//copy bedroom 1 pic
if($bdrm1_name !="")
{
copy ("$bdrm1", "./pictures/$bdrm1_name")
or die("Bedroom 1: Could not copy file.");
echo "Bedroom 1: File $bdrm1_name Uploaded Successfuly<br>";
}
else {die("Bedroom 1: No file specified for Bedroom 1 Picture.");}
//copy bedroom 2 pic
if($bdrm2_name !="")
{
copy ("$bdrm2", "./pictures/$bdrm2_name")
or die("Bedroom 2: Could not copy file.");
echo "Bedroom 2: File $bdrm2_name Uploaded Successfuly<br>";
}
else {die("Bedroom 2: No file specified Bedroom 2 Picture.");}
Example: If someone chooses not to upload a $mainpic for this house but they do uplaod pictures of the bedrooms, the Bedroom pictures never get copied to my picture directory. It more or less stops parsing the code right after the first variable that is empty. I know the code works if a user specifies files to upload for all possible variables.
Any one know what I need to add to make this work?
Thanks!