Advertisement
mttprvst13

HTML file(With php)

Feb 14th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.10 KB | None | 0 0
  1. <?php
  2. $error = array();
  3. if(isset($_POST['submit'])){
  4.    if(!isset($_POST['name']) || $_POST['name'] == ''){
  5.        $error[1] = 'Please enter the name form.';
  6.    }
  7.    if(!isset($_POST['lang']) || $_POST['lang'] == array()){
  8.        $error[2] = 'Please enter the language form.';
  9.    }
  10.    if(!isset($_POST['desc']) || $_POST['desc'] == ''){
  11.        $error[3] = 'Please enter the description form.';
  12.    }
  13.    if(!isset($_POST['file']) || $_POST['file'] == ''){
  14.        $error[4] = 'Please select a file.';
  15.    }
  16.    if(isset($error) && $error != array()){
  17.        foreach($error as $e => $k){
  18.             echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> ' . $k . '</div>';
  19.         }
  20.     }else{
  21.         $data = array();
  22.         $data['name'] = $db->mySQLSafe($_POST['name']);
  23.         $data['file'] = $db->mySQLSafe(serialize($_POST['file']));
  24.         $data['description'] = $db->mySQLSafe($_POST['desc']);
  25.         $data['author'] = $db->mySQLSafe($result[0]['full name']);
  26.         $data['page'] = $db->mySQLSafe('projects');
  27.        
  28.         $insert = $db->insert('projects', $data);
  29.         if($insert){
  30.             $target_file = 'projects/' . basename($_FILES["file"]["name"]);
  31.             $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
  32.             echo $target_file . '<br />';
  33.             echo $fileType . '<br />';
  34.             $uploadok = 1;
  35.             if (file_exists($target_file)) {
  36.                 echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That file already exists, try a different file name.</div>';
  37.                 $uploadok = 0;
  38.             }
  39.             if ($_FILES["file"]["size"] > 500000) {
  40.                 echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That file is too large.</div>';
  41.                 $uploadok = 0;
  42.             }
  43.             if($fileType != 'zip' && $fileType != 'gz' && $fileType != 'java' && $fileType != 'py' && $fileType != 'html' && $fileType != 'css' && $fileType != 'js'){
  44.                echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That type of file is not acceptable.</div>';
  45.                 $uploadok = 0;
  46.             }
  47.             if($uploadok == 0){
  48.                 echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> The file was not uploaded.</div>';
  49.             }else{
  50.                 if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){
  51.                     echo '<div class="alert alert-success" role="alert"><strong>Yes!</strong> It was successfully submitted!</div>';
  52.                 }else{
  53.                     echo '<div class="alert alert-warning" role="alert"><strong>Warning!</strong> There was an error uploading your file with error code ' . $_FILES['file']['error'] . '.</div>';
  54.                 }
  55.             }
  56.         }else{
  57.             echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> There was an error inserting the data.</div>';
  58.         }
  59.     }
  60. }
  61. ?>
  62.  
  63. <form class="form-horizontal" method="POST" enctype="multipart/form-data">
  64.     <!--
  65.    <div class="form-group">
  66.        <label for="id" class="col-sm-2 control-label">Text</label>
  67.        <div class="col-sm-10">
  68.            <input type="text" class="form-control" name="name" id="id" placeholder="placeholder">
  69.        </div>
  70.    </div>
  71.    -->
  72.     <div class="form-group">
  73.         <label for="name" class="col-sm-2 control-label">Name of the Program</label>
  74.         <div class="col-sm-10">
  75.             <input type="text" class="form-control" name="name" id="name" placeholder="Name">
  76.         </div>
  77.     </div>
  78.     <div class="form-group">
  79.         <label for="lang" class="col-sm-2 control-label">What language is it in</label>
  80.         <div class="col-sm-10">
  81.             <select multiple class="form-control" id="lang" name="lang[]">
  82.                 <option value="java">Java</option>
  83.                 <option value="python">Python</option>
  84.                 <option value="webiste">Website(HTML, PHP, CSS or Javascript)</option>
  85.             </select>
  86.         </div>
  87.         <span id="helpBlock" class="help-block">Hold down control to select multiple.</span>
  88.     </div>
  89.     <div class="form-group">
  90.         <label for="desc" class="col-sm-2 control-label">Give a description about it</label>
  91.         <div class="col-sm-10">
  92.             <textarea id="desc" name="desc" class="form-control" rows="4" placeholder="Description"></textarea>
  93.         </div>
  94.     </div>
  95.     <div class="form-group">
  96.         <label for="file" class="col-sm-2 control-label">Upload the file</label>
  97.         <div class="col-sm-10">
  98.             <input type="hidden" name="MAX_FILE_SIZE" value="500000" />
  99.             <input type="file" class="form-control file" name="file" id="file" placeholder="File">
  100.         </div>
  101.         <span id="helpBlock" class="help-block">If it is in multiple files put it in a ZIP file.</span>
  102.     </div>
  103.     <div class="form-group">
  104.         <div class="col-sm-offset-2 col-sm-10">
  105.             <button type="submit" name="submit" class="btn btn-default">Continue</button>
  106.         </div>
  107.     </div>
  108. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement