Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $error = array();
- if(isset($_POST['submit'])){
- if(!isset($_POST['name']) || $_POST['name'] == ''){
- $error[1] = 'Please enter the name form.';
- }
- if(!isset($_POST['lang']) || $_POST['lang'] == array()){
- $error[2] = 'Please enter the language form.';
- }
- if(!isset($_POST['desc']) || $_POST['desc'] == ''){
- $error[3] = 'Please enter the description form.';
- }
- if(!isset($_POST['file']) || $_POST['file'] == ''){
- $error[4] = 'Please select a file.';
- }
- if(isset($error) && $error != array()){
- foreach($error as $e => $k){
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> ' . $k . '</div>';
- }
- }else{
- $data = array();
- $data['name'] = $db->mySQLSafe($_POST['name']);
- $data['file'] = $db->mySQLSafe(serialize($_POST['file']));
- $data['description'] = $db->mySQLSafe($_POST['desc']);
- $data['author'] = $db->mySQLSafe($result[0]['full name']);
- $data['page'] = $db->mySQLSafe('projects');
- $insert = $db->insert('projects', $data);
- if($insert){
- $target_file = 'projects/' . basename($_FILES["file"]["name"]);
- $fileType = pathinfo($target_file,PATHINFO_EXTENSION);
- echo $target_file . '<br />';
- echo $fileType . '<br />';
- $uploadok = 1;
- if (file_exists($target_file)) {
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That file already exists, try a different file name.</div>';
- $uploadok = 0;
- }
- if ($_FILES["file"]["size"] > 500000) {
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That file is too large.</div>';
- $uploadok = 0;
- }
- if($fileType != 'zip' && $fileType != 'gz' && $fileType != 'java' && $fileType != 'py' && $fileType != 'html' && $fileType != 'css' && $fileType != 'js'){
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> That type of file is not acceptable.</div>';
- $uploadok = 0;
- }
- if($uploadok == 0){
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> The file was not uploaded.</div>';
- }else{
- if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)){
- echo '<div class="alert alert-success" role="alert"><strong>Yes!</strong> It was successfully submitted!</div>';
- }else{
- 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>';
- }
- }
- }else{
- echo '<div class="alert alert-danger" role="alert"><strong>Error!</strong> There was an error inserting the data.</div>';
- }
- }
- }
- ?>
- <form class="form-horizontal" method="POST" enctype="multipart/form-data">
- <!--
- <div class="form-group">
- <label for="id" class="col-sm-2 control-label">Text</label>
- <div class="col-sm-10">
- <input type="text" class="form-control" name="name" id="id" placeholder="placeholder">
- </div>
- </div>
- -->
- <div class="form-group">
- <label for="name" class="col-sm-2 control-label">Name of the Program</label>
- <div class="col-sm-10">
- <input type="text" class="form-control" name="name" id="name" placeholder="Name">
- </div>
- </div>
- <div class="form-group">
- <label for="lang" class="col-sm-2 control-label">What language is it in</label>
- <div class="col-sm-10">
- <select multiple class="form-control" id="lang" name="lang[]">
- <option value="java">Java</option>
- <option value="python">Python</option>
- <option value="webiste">Website(HTML, PHP, CSS or Javascript)</option>
- </select>
- </div>
- <span id="helpBlock" class="help-block">Hold down control to select multiple.</span>
- </div>
- <div class="form-group">
- <label for="desc" class="col-sm-2 control-label">Give a description about it</label>
- <div class="col-sm-10">
- <textarea id="desc" name="desc" class="form-control" rows="4" placeholder="Description"></textarea>
- </div>
- </div>
- <div class="form-group">
- <label for="file" class="col-sm-2 control-label">Upload the file</label>
- <div class="col-sm-10">
- <input type="hidden" name="MAX_FILE_SIZE" value="500000" />
- <input type="file" class="form-control file" name="file" id="file" placeholder="File">
- </div>
- <span id="helpBlock" class="help-block">If it is in multiple files put it in a ZIP file.</span>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <button type="submit" name="submit" class="btn btn-default">Continue</button>
- </div>
- </div>
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement