Guest User

image upload problem

a guest
Mar 30th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 10.49 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. include ('config.php');
  4.       // case start for upload & insert
  5.       define ("MAX_SIZE","9000");
  6.       function getExtension($str)
  7.       {
  8.                $i = strrpos($str,".");
  9.                if (!$i) { return ""; }
  10.                $l = strlen($str) - $i;
  11.                $ext = substr($str,$i+1,$l);
  12.                return $ext;
  13.       }
  14.       $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","mp4","pdf");
  15.       if(isset($_POST['case_form']))
  16.       {
  17.           $client_save = $_POST['client'];
  18.           $client_explode = explode('|', $client_save);
  19.           $client_capp = $_POST['capp'];
  20.           $client_tpolicy = $_POST['tpolicy'];
  21.           $client_camt = $_POST['camt'];
  22.           $client_desc = $_POST['desc'];
  23.  
  24.           if ($valid_formats) {
  25.             $caseqry2 = mysqli_query($connection , "INSERT INTO crm_case(`case_cname`, `case_capp`, `case_tpolicy`, `case_camt`, `case_desc`, `case_status`, `case_cid`, `case_mid`) VALUES ('$client_explode[0]','$client_capp','$client_tpolicy','$client_camt','$client_desc','0','$client_explode[1]','".$_SESSION['user_id']."')") or die(mysqli_error());
  26.            
  27.                 if ($caseqry2) {
  28.                     $msg = "Success";
  29.                     $msg1 = base64_encode($msg);
  30.  
  31.                   } else {
  32.                     $msg = "Failed";
  33.                     $msg1 = base64_encode($msg);
  34.                   }
  35.           }
  36.           $lastid_case = mysqli_insert_id($connection);
  37.  
  38.             print_r($_POST);
  39.             print_r($_FILES);
  40.             exit;
  41.           // start file case file uploads
  42.           $uploaddir = "../uploadcase/"; //a directory inside
  43.           foreach ($_FILES['photos']['name'] as $name => $value)
  44.           {
  45.               $filename = stripslashes($_FILES['photos']['name'][$name]);
  46.               $casefile_titleexplod = stripslashes($_POST['filenam'][$name]);
  47.               $size=filesize($_FILES['photos']['tmp_name'][$name]);
  48.               //get the extension of the file in a lower case format
  49.                 $ext = getExtension($filename);
  50.                 $ext = strtolower($ext);  
  51.                if(in_array($ext,$valid_formats))
  52.                {
  53.                      if ($size < (MAX_SIZE*1024))
  54.                      {
  55.                        $image_name=time().$filename;
  56.                        //echo "<img src='".$uploaddir.$image_name."' class='imgList'>";
  57.                        $newname=$uploaddir.$image_name;
  58.                        if (move_uploaded_file($_FILES['photos']['tmp_name'][$name], $newname))
  59.                        {
  60.                        echo "INSERT INTO crm_case_file(`case_id`,`casefile_name`,`casefile_title`,`casefile_mid`,`casefile_cid`,`casefile_status`) VALUES('$lastid_case','$image_name','$casefile_titleexplod','".$_SESSION['user_id']."','$client_explode[1]','0')";
  61.  
  62.                         mysqli_query($connection , "INSERT INTO crm_case_file(`case_id`,`casefile_name`,`casefile_title`,`casefile_mid`,`casefile_cid`,`casefile_status`) VALUES('$lastid_case','$image_name','$casefile_titleexplod','".$_SESSION['user_id']."','$client_explode[1]','0')");
  63.                        }
  64.                        else
  65.                         {
  66.                         echo '<span class="imgList">You have exceeded the size limit! so moving unsuccessful! </span>';
  67.                         }
  68.                     }
  69.                     else
  70.                     {
  71.                     echo '<span class="imgList">You have exceeded the size limit!</span>';
  72.                     }    
  73.                 }
  74.                 else
  75.                 {
  76.                 echo '<span class="imgList">Unknown extension!</span>';  
  77.                 }
  78.            }
  79.            // header("Location:caseconsultations.php?msg=".$msg1);
  80.       }
  81.    // case end
  82. ?>
  83.  
  84.  <form action="" method="post" enctype="multipart/form-data" style="clear:both" onsubmit="LoadData()" id="form_sample_2" novalidate="novalidate">
  85.  
  86.                 <div class="form-group col-xs-12">
  87.                 <label class="control-label">* Client Name - if client is not added to "All Clients",add them <a href="client-add.php">here</a> first</label>
  88.                 <select required="" class="form-control" name="client">
  89.                   <option value="">Client Name</option>
  90.                   <?php
  91.                   $fetchstate= mysqli_query($connection, "SELECT * FROM crm_client where m_id = '".$_SESSION['user_id']."'");
  92.                   while ($staterow=mysqli_fetch_array($fetchstate))
  93.                   {
  94.                   $stateTitle= $staterow['c_name'];
  95.                   $stateTitle2= $staterow['id'];
  96.                   ?>
  97.                   <option value="<?php echo $stateTitle ;?>|<?php echo $stateTitle2 ;?>"><?php echo $stateTitle ;?></option>
  98.                   <?php } ?>
  99.                  </select>
  100.                 </div>
  101.  
  102.                <div class="form-group col-md-4 col-xs-12">
  103.                <div class='field'>
  104.                    <label class="control-label">* Carrier of Application</label>
  105.                    <input type="text" name="capp" value="" required="" class="form-control" placeholder="John Hancock" id="validform">
  106.                    </div>
  107.                </div>
  108.  
  109.                <div class="form-group col-md-4 col-xs-12">
  110.                               <label class="control-label">* Type of Policy</label>
  111.                               <select required="required" class="form-control" name="tpolicy">
  112.                               <option value="">Selcet Policy</option>
  113.                               <option value="5 year term">5 year term</option>
  114.                               <option value="10 year term">10 year term</option>
  115.                               <option value="20 year term">20 year term</option>
  116.                               <option value="30 year term">30 year term</option>
  117.                               <option value="10 year Return of Premium">10 year Return of Premium</option>
  118.                               <option value="20 year Return of Premium">20 year Return of Premium</option>
  119.                               <option value="30 year Return of Premium">30 year Return of Premium</option>
  120.                               <option value="Whole Life">Whole Life</option>
  121.                               <option value="Universal Life - Traditional">Universal Life - Traditional</option>
  122.                               <option value="Universal Life - Indexed">Universal Life - Indexed</option>
  123.                               <option value="10 Pay Limited Pay">10 Pay Limited Pay</option>
  124.                               <option value="15 Pay Limited Pay">15 Pay Limited Pay</option>
  125.                               <option value="20 Pay Limited Pay">20 Pay Limited Pay</option>
  126.                               </select>
  127.               </div>
  128.  
  129.               <div class="form-group col-md-4 col-xs-12">
  130.                               <label class="control-label">* Coverage Amount</label>
  131.                               <div id="caseamt" class="input-group col-md-12"> <span style="position:relative !important;" class="input-group-addon">$</span>
  132.                               <input value="" required="required" maxlength="6"  class="form-control" aria-label="Amount (to the nearest dollar)" name="camt" type="text" id="maskamount">
  133.                                 <script type="text/javascript">                    
  134.                             document.getElementById('maskamount').addEventListener('input', function (e) {
  135.                             var x = e.target.value.replace(/\D/g, '').match(/(\d{0,3})(\d{0,3})(\d{0,4})/);
  136.                             e.target.value = !x[2] ? x[1] :  + x[1] + x[2] + (x[3] ? '-' + x[3] : '');
  137.                             });
  138.                             </script>
  139.                              
  140.                           <span style="position:relative;!important;" class="input-group-addon">.00</span> </div>
  141.                                
  142.               </div>
  143.  
  144.               <div class="form-group col-md-12 col-xs-12">
  145.                 <label class="control-label">Description</label>
  146.                 <textarea class="form-control" name="desc" placeholder="Case Description"></textarea>
  147.  
  148.               </div>
  149.  
  150.               <div class="form-group col-xs-12">
  151.                 <input type="hidden" name="nameid" value="">
  152.                           <label for="picture">* Upload Files For Client</label>
  153.              <input required="" class="form-control" style="height:auto;" name="photos[]" id="uploadfile" multiple="true" type="file">
  154.                          
  155.                           <div class="col-xs-12">
  156.                          <div col-md-6 id="filelist" style="display:none;"> </div>
  157.                          <div col-md-6 id="fileinputtag"> </div>
  158.                          <div col-md-6 id="list"> </div>
  159.                          </div>
  160.  
  161.  
  162.                       <script>
  163.                       function handleFileSelect(evt) {
  164.                           var files = evt.target.files; // FileList object
  165.                           // Loop through the FileList and render image files as thumbnails.
  166.                           for (var i = 0, f; f = files[i]; i++) {
  167.                             // Only process image files.
  168.                             var reader = new FileReader();
  169.                             // Closure to capture the file information.
  170.                             reader.onload = (function(theFile) {
  171.                               return function(e) {
  172.                                 //Render thumbnail.
  173.                                 var span = document.createElement('span');
  174.                            span.innerHTML = ['<p>',escape(theFile.name),'</p><input type="text" name="filenam[]" value="">'].join('');
  175.                                 document.getElementById('list').insertBefore(span, null);
  176.                               };
  177.                             })(f);
  178.                             // Read in the image file as a data URL.
  179.                             reader.readAsDataURL(f);
  180.                           }
  181.                         }
  182.                         document.getElementById('uploadfile').addEventListener('change', handleFileSelect, false);*/
  183.                         </script>
  184.               </div>
  185.              
  186.               <div class="inner-content col-md-12 text-center">
  187.                 <div class='actions'>
  188.                   <input type="submit" class="btn btn-success" value="SUBMIT" name="case_form" />
  189.                   </div>
  190.               </div>
  191.               <div class="col-md-12">&nbsp;</div>
  192.           </form>
Add Comment
Please, Sign In to add comment