php code is not catching errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wadedavis
Forum Newbie
Posts: 2
Joined: Sun Jan 25, 2004 4:44 am

php code is not catching errors

Post by wadedavis »

Anybody have any suggestion as to why this code is not catching errors

Code: Select all

<?php

if ($HTTP_POST_VARS['submit']) {
  print ($bandname);
  if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) {
    $error = "You did not upload a file!";
    unlink($HTTP_POST_FILES['file']['tmp_name']);
    // assign error message, remove uploaded file, redisplay form.
  } else {
    //a file was uploaded
    $maxfilesize=500240;
	

    if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) {
      $error = "photo is too large";
      unlink($HTTP_POST_FILES['file']['tmp_name']);
      // assign error message, remove uploaded file, redisplay form.
    } else {
      if ($HTTP_POST_FILES['file']['type'] != "image/gif" AND $HTTP_POST_FILES['file']['type'] != "image/pjpeg") { 
        $error = "This file type is not allowed";
        unlink($HTTP_POST_FILES['file']['tmp_name']);
        // assign error message, remove uploaded file, redisplay form.
      } else {
       //File has passed all validation, copy it to the final destination and remove the temporary file:
       copy($HTTP_POST_FILES['file']['tmp_name'],"/home/httpd/vhosts/springscream.com/httpdocs/ssbandphotoupload/".$HTTP_POST_FILES['file']['name']);
       unlink($HTTP_POST_FILES['file']['tmp_name']);
	     if (!is_uploaded_file($HTTP_POST_FILES['file2']['tmp_name'])) {
    $error = "Got it. Thanks!";
	mail("wade@springscream.com","Photos from $bandname","Photos $file, $file2, $file3 has be sent to http://wwww.springscream.com/uploadbandphotos/","From: $email");
       print ", your photo(s) has been successfully uploaded!&#25910;&#21040;&#20102;&#35613;&#35613;!";
    exit;
    // assign error message, remove uploaded file, redisplay form.
  } else {
if ($HTTP_POST_FILES['file2']['size'] > $maxfilesize) {
      $error = "photo2 is too large";
      unlink($HTTP_POST_FILES['file2']['tmp_name']);
      // assign error message, remove uploaded file, redisplay form.
    } else {
      if ($HTTP_POST_FILES['file2']['type'] != "image/gif" AND $HTTP_POST_FILES['file2']['type'] != "image/pjpeg") { 
        $error = "This file type is not allowed";
        unlink($HTTP_POST_FILES['file2']['tmp_name']);
        // assign error message, remove uploaded file, redisplay form.
      } else {
       //File has passed all validation, copy it to the final destination and remove the temporary file:
       copy($HTTP_POST_FILES['file2']['tmp_name'],"/home/httpd/vhosts/springscream.com/httpdocs/ssbandphotoupload/".$HTTP_POST_FILES['file2']['name']);
       unlink($HTTP_POST_FILES['file2']['tmp_name']);
	   if (!is_uploaded_file($HTTP_POST_FILES['file3']['tmp_name'])) {
    $error = "Got it. Thanks!";
	mail("wade@springscream.com","Photos from $bandname","Photos $file, $file2, $file3 has be sent to http://wwww.springscream.com/uploadbandphotos/","From: $email");
       print ", your photo(s) has been successfully uploaded!&#25910;&#21040;&#20102;&#35613;&#35613;!!";
    exit;
	} else {
  	   if ($HTTP_POST_FILES['file3']['size'] > $maxfilesize) {
      $error = "photo3 is too large";
      unlink($HTTP_POST_FILES['file3']['tmp_name']);
      // assign error message, remove uploaded file, redisplay form.
    } else {
      if ($HTTP_POST_FILES['file3']['type'] != "image/gif" AND $HTTP_POST_FILES['file3']['type'] != "image/pjpeg") { 
        $error = "This file type is not allowed";
        unlink($HTTP_POST_FILES['file3']['tmp_name']);
        // assign error message, remove uploaded file, redisplay form.
      } else {
       //File has passed all validation, copy it to the final destination and remove the temporary file:
       copy($HTTP_POST_FILES['file3']['tmp_name'],"/home/httpd/vhosts/springscream.com/httpdocs/ssbandphotoupload/".$HTTP_POST_FILES['file3']['name']);
       unlink($HTTP_POST_FILES['file3']['tmp_name']);
	   
	   mail("wade@springscream.com","Photos from $bandname","Photos $file, $file2, $file3 has be sent to http://wwww.springscream.com/uploadbandphotos/","From: $email");
       print ", your photos and logos have been successfully uploaded!. &#25910;&#21040;&#20102;&#35613;&#35613;!!!<A HREF="index.htm" TARGET="_blank">Home</A> ";
	   echo "<A HREF="index.htm" TARGET="_blank">Home</A>";
       exit;
     }
    } 
  }
}
}
}
}
}
}
}

?>


<html>
<head>
<title>Spring Scream Band Photos</title>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<script language="JavaScript">
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<div id="Layer1" style="position:absolute; left:23px; top:341px; width:450px; height:227px; z-index:1"> 
  <form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
    <div align="center">
      <table width="81%" border="1">
        <tr>
          <td>
            <div align="center"> 
              <p align="center">Your Band Name &#20320;&#30340;&#22296;&#21517; 
                <input type="text" name="bandname" size="40" maxlength="70">
              </p>
              <p align="center">Your Band Email&#20320;&#22296;&#30340;email 
                <input name="email" type="text" id="email" size="30" maxlength="30">
                <br>
                <br>
                photo1..... 
                <input type="file" name="file">
              </p>
              <p align="center"> photo2 ..... 
                <input type="file" name="file2">
              </p>
              <p align="center"><font size="3">LOGO....</font> 
                <input type="file" name="file3">
              </p>
              <p align="center"><br>
                <input type="submit" name="submit" value="send">
              </p>
            </div>
  </td>
        </tr>
      </table>
    </div>
  </form>
</div>
<div id="Layer2" style="position:absolute; left:37px; top:23px; width:424px; height:241px; z-index:2"> 
  <p align="center"><font size="4">Upload Your Band Photos Here.....&#19978; &#20659; &#20320; &#27138; &#22296; &#30340; &#29031; &#29255; &#22312; &#36889; &#37002;.....</font></p>
  <p align="center"><font size="4">Photo file format must be <font color="#FF9900">.jpg</font> 
    or <font color="#FF9900">.gif</font> and must be under <font color="#FF9900">200kb</font> 
    in size.&#21487; &#29992; &#30340; &#26684; &#24335; &#26159; <font color="#FF9900">.jpg</font>&#21644;<font color="#FF9900">.gif</font>&#21644; &#22823; &#23567; &#19981; &#21487; &#20197; &#36229; &#36942;<font color="#FF9900">200kb</font></font></p>
  <p align="center">Remember to make sure that the photos' filename is your<strong><font color="#FF9900"> 
    Band Name</font></strong>. &#19981; &#35201; &#24536; &#35352; &#25226; &#20320; &#20497; &#29031; &#29255; &#30340; &#27284; &#21517; &#25913; &#21040; &#20320; &#20497; &#30340;<font color="#FF9900">&#22296;&#21517;</font></p>
  <p align="center">And name them with numbers like this.......</p>
  <p align="center"><font color="#000000">Ex: dribdas1.jpg, dribdas2.jpg, dribdaslogo.jpg 
    &#20363; &#22914; :&#34367; &#34068; &#33151; 1.jpg, &#34367; &#34068; &#33151; 2.jpg, &#34367; &#34068; &#33151; logo.jpg</font></p>
  <p align="center">&nbsp;</p>
</div>
</body>
</html>
User avatar
AVATAr
Forum Regular
Posts: 524
Joined: Tue Jul 16, 2002 4:19 pm
Location: Uruguay -- Montevideo
Contact:

Post by AVATAr »

first use php tags
[Admin Edit: Added these to original post (only because there was a tiny bit of indenting that could possibly be useful)]

what version of php are you using? have you globals off?
what erro do you want to catch?
try ussing $_POST & $_FILES instead of $HTTP_POST ... $HTTP_POST_FILES
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

What errors aren't being caught. Lots of code with little explanation is difficult to debug.

Mac
wadedavis
Forum Newbie
Posts: 2
Joined: Sun Jan 25, 2004 4:44 am

more info

Post by wadedavis »

if I don't upload any images it should not allow me to submit....Also I have tried to upload a large file size and it allows that too. I want it to catch anything over 500k......I am using php 4.....
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

OMFG ... ever heard of white space ? or funcitons ?

Bad code makes baby jesus cry =P
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Have you tried cutting the code down - getting one thing to work and then adding the next? The lack of whitespace and confused indenting does make that code very hard to read and thus it is difficult for you to help yourself and us to help you.

Mac
Post Reply