Advertisement
Guest User

Untitled

a guest
Nov 8th, 2013
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.20 KB | None | 0 0
  1. <?php
  2. LOGIN CREDENTIALS ARE HERE - REMOVED FOR PRIVACY OF CLIENT
  3. ?>
  4. <?
  5. $picid = $_POST["picid"];
  6. $action = $_POST["action"];
  7.  
  8. if ($action == "add") {
  9.     $depname = $_POST["depname"];
  10.     $deptitle = $_POST["deptitle"];
  11.     $depimage =  basename($_FILES['depimage']['name']);
  12.     $picture = $_FILES["depimage"]["name"];
  13.    
  14.     //Any error except "No File Uploaded (4)" gets handled here:
  15.     if (($_FILES["depimage"]["error"] > 0) && ($_FILES["depimage"]["error"] != 4) )
  16.      {
  17.         echo "Error: " . $_FILES["depimage"]["error"] . "<br />";
  18.      }
  19.     else
  20.      {
  21.         //No File, no name and no title means we just skip it.
  22.         if (($_FILES["depimage"]["error"] == 4) && ($depname == '') && ($deptitle == '')) {
  23.             echo "No information entered.";
  24.         }
  25.         else if (($_FILES["depimage"]["error"] == 4) && ($depname != '') && ($deptitle != ''))
  26.         //Data was entered for title and name but not file.
  27.         {
  28.             $picture = "imagenotfound.jpg";
  29.                 $query = "UPDATE deputies SET name='$depname', title='$deptitle', photo='$picture' WHERE id = $picid";
  30.                 $result = mysql_query($query);
  31.                 mysql_close();
  32.                 if ($result) {
  33.                     print('Add Officer was successful.  Press the "Close Window" button below to close this window and refresh the editor.<br><br>');
  34.                     print('<span width="100%" align="center"><a href="javascript:window.close();">Close this Window</span>');
  35.                 }
  36.        
  37.         }
  38.         //All data was entered
  39.         else
  40.         {
  41.             if (file_exists("images/deputies/photos/" . $_FILES["depimage"]["name"]))
  42.              {
  43.                 echo $_FILES["depimage"]["name"] . " already exists.<br />";
  44.              }
  45.             else
  46.              {
  47.                 $final_file_path = "images/deputies/photos/" . basename($_FILES["depimage"]["name"]);
  48.                 move_uploaded_file($_FILES["depimage"]["tmp_name"],$final_file_path);
  49.                 chmod($final_file_path,0777);
  50.                 $query = "UPDATE deputies SET name='$depname', title='$deptitle', photo='$picture' WHERE id = $picid";
  51.                 $result = mysql_query($query);
  52.                 mysql_close();
  53.                 if ($result) {
  54.                     print('Add Officer was successful.  Press the "Close Window" button below to close this window and refresh the editor.<br><br>');
  55.                     print('<span width="100%" align="center"><a href="javascript:window.close();">Close this Window</span>');
  56.                 }
  57.              }
  58.         }
  59.      }
  60. }
  61.  
  62.  
  63. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement