Im using the following to upload a single image file. The form works to limit the size of the file (If the file is over 500k it won't be uploaded). However - my error handling doesn't seem to be working correctly. I've left out the code thats not associated with the image upload below for the most part.
Anyone have any ideas?
<script language=javascript>
extArray = new Array(".jpg", ".jpeg",".gif"); //".png", , ".gif"
function callSave()
{
if(!isCurrency(document.frmlisting.txtlistingprice.value)){
alert("Price: Incorrect data");
document.frmlisting.txtlistingprice.select();
return;
}
if(isBlank(document.frmlisting.txtlistingtitle.value)){
alert("Title is Required");
document.frmlisting.txtlistingtitle.focus();
return;
}
if(!isBlank(document.frmlisting.txtlistingimage.value)){
if(!isValidFile(document.frmlisting.txtlistingimage.value)){
alert("Selected file is not a vaild image type. \nPlease select "+ (extArray.join(" ").toUpperCase())+ " files. ");
document.frmlisting.txtlistingimage.select();
return;
}
}
if(isBlank(document.frmlisting.txtlistingemail.value)){
alert("Email is Required");
document.frmlisting.txtlistingemail.select();
return;
}
if(!isEmail(document.frmlisting.txtlistingemail.value)){
alert("Email: Incorrect data");
document.frmlisting.txtlistingemail.select();
return;
}
document.frmlisting.action="listingsubmit.php";
document.frmlisting.submit();
}
</script>
<FORM name="frmlisting" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="500000">
<Input type="file" name="txtlistingimage" style="WIDTH: 275px; HEIGHT: 20px" size="39" maxlength="100">
<Input type=hidden name="mode" value="<?=$mode?>">
<input type=hidden name="l_id" value="<?=$l_id?>">
<input type=hidden name="c_id" value="<?=$c_id?>">
<input type=hidden name="cboCity" value="<?=$intcityid?>">
<input type=hidden name="txtpreviousimage" value="<?=$listingimage?>">
<input type=hidden name="txtfrmpg" value='<?=$frmpg?>'>
<input type="button" class="btn_text" value="Preview" onclick="javascript:callSave();" style="border:solid-1px; color: #333333 ">
The processor "listingsubmit.php"
<?
$frmpg = $HTTP_POST_VARS['txtfrmpg'];
$dirupload = "images/listing/";
switch ($mode){
case "Add":
//-- GET SIZE OF UPLOAD IMAGE
/*== only allow images smaller than 600 x 600 ==*/
$imgsize = GetImageSize('txtlistingimage');
/*== check size 0=width, 1=height ==*/
if (($imgsize[0] > 600) || ($imgsize[1] > 600))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
print "Your File is to large. Maximum file dimensions are 600px x 600px.";
exit();
}
$max_filesize_k = ($max_filesize / 500);
if($_FILES['txtlistingimage']['size'] > $max_filesize)
{
echo "Your file is too large. Files may be up to ".$max_filesize_k."K\n";
include("listingentry.php");
exit;
}
//-- END GET SIZE OF UPLOAD IMAGE
if($HTTP_POST_FILES['txtlistingimage']['name'] == ""){
$listing_image = "";
}else{
$listing_image = getfilename($HTTP_POST_FILES['txtlistingimage']['name'],1);
copy ( $HTTP_POST_FILES['txtlistingimage']['tmp_name'],$dirupload.$listing_image)
or $msgid=2;
}