I'm working with the script below, and for the life of me I cannot get it to run the way I want. I'm new to PHP, so excuse me if this may be something very obvious.
Purpose of script: process a form that allows visitors to send the site owner their name, email and question (required fields); visitor has option to upload one, two or no images; info added to database and details emailed to site owner.
Problem: Error received unless visitor submits two images. I'm assuming the problem lies with the two if statements checking to see if the files were uploaded. The rest of the script that I've clipped goes on to email the webmaster and add to the database. How do I set this up to basically skip over any reference to the files unless files have in fact been uploaded?
<?php
include("global.inc.php");
$errors=0;
$error="The following errors occured while processing your form input.<ul>";
pt_register('POST','name');
pt_register('POST','email');
$photo1=$HTTP_POST_FILES['photo1'];
$photo2=$HTTP_POST_FILES['photo2'];
pt_register('POST','question');
$question=preg_replace("/(\015\012)|(\015)|(\012)/"," <br />", $question);if($name=="" || $email=="" || $question=="" ){
$errors=1;
$error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
}
if(!is_uploaded_file($HTTP_POST_FILES['photo1']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['photo1']['name'].", was not uploaded!";
$errors=1;
}
if(!is_uploaded_file($HTTP_POST_FILES['photo2']['tmp_name'])){
$error.="<li>The file, ".$HTTP_POST_FILES['photo2']['name'].", was not uploaded!";
$errors=1;
}
if($errors==1) echo $error;
else{
$image_part = date("h_i_s")."".$HTTP_POST_FILES['photo1']['name'];
$image_list[2] = $image_part;
copy($HTTP_POST_FILES['photo1']['tmp_name'], "files/".$image_part);
$image_part = date("h_i_s")."".$HTTP_POST_FILES['photo2']['name'];
$image_list[3] = $image_part;
copy($HTTP_POST_FILES['photo2']['tmp_name'], "files/".$image_part);
$where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
[snip,snip]
?>